I am trying to create a .NET list of F# functions, but it keeps telling me that it expects a something something, but has a 'a instead. I'm not sure, but I'm guessing it's because I can't create a .NET list of F# functions. Is this true?
For example, when I try:
let listOfFunctions = new List<int -> unit>()
The compiler complains accordingly:
No constructors are available for the type 'List<(int -> unit)>'
EDIT
After much thought, I realized, I forgot to open System.Collections.Generic, which caused the issue. I didn't notice the issue because the compiler thought it was an F# list, which doesn't have a constructor like .NET Lists do. However, it's confusing because the type signatures look the same. Consider the following code:
let FSharpList : List<int> = [1;2;3]
let DotNetList : List<int> = new List<int>()
If you don't use open System.Collections.Generic, the compiler assumes List to be an F# list, and the second line will obviously fail. But if you include it, then the compiler will assume List is a .NET list, and the first line will complain that [1;2;3] is supposed to have type List<int>
but instead has type 'a list
(aka it's expecting a .NET list).
So actually, it had nothing to do with a list of functions at all. In fact, the following code:
open System.Collections.Generic
let myList = new List<int -> unit>()
works just fine.