Following this from the Real-World Functional Programming blog about drawing bar and column charts, I was trying to draw a histogram for my data which is stored at a set of tuples (data_value, frequency) in a lazy sequence.
It does not work unless I convert the sequence into a List, the error message being that in case of sequence “the IEnumerable 'T does not support the Reset function“. Is there any way to generate a histogram/chart etc. using the .NET library from a lazily-evaluated sequence?
Also (ok newbie query alert), is there any way to make the chart persist when the program is run from the console? The usual System.Console.ReadKey() |> ignore makes the chart window hang, and otherwise it disappears in an instant. I’ve been using “Send to Interactive” to see results til now.
The problem is that sequences (of type
seq<T>, which is just an alias forIEnumerable<T>) generated using the F# sequence expression notation do not support theResetmethod. The method is required by the charting library (because it needs to obtain the data each time it redraws the screen).This means that, for example, the following will not work:
Many of the standard library functions from the
Seqmodule are implemented using sequence expressions, so the result will not supportReset. You can fix that by converting the data to a list (usingList.ofSeq) or to an array (usingArray.ofSeq) or by writing the code using lists:… and if you’re using some function, you can take the one from
List(not all of theSeqfunctions are available forList, so sometimes you will need to use conversion):