If you want to create a method that takes params
array of functions, then you need to define the parameter as [<ParamArray>] funcs: (float -> float)[]
. In your original version, the type was Object[]
meaning that individual elements of the array were objects - if you change the type of elements to functions, then F# will recognize that you can call them.
However, if you're simply interested in charting F# data, then there is already a good wrapper for the WinForms DataVisualization library called F# Chart and available on GitHub. There is also a comprehensive documentation available on MSDN (if you use the latest version of the library, then FSharpChart
has been renamed to just Chart
).
To create a plot comparing two functions over a specified range, you can simply write:
let plotTwoFunctions minX maxX f1 f2 =
Chart.Combine
[ Chart.Line [ for x in minX .. maxX -> x, f1 x ]
Chart.Line [ for x in minX .. maxX -> x, f2 x ] ]
This creates two individual line charts (with data generated by the two functions) and then combines them into a single chart using Chart.Combine
.