I created a type Person as follows which runs fine.
type Person =
{ First: string; Last : string }
override this.ToString() = sprintf "%s, %s" this.First this.Last
But when I try to make a list of Person as follows.
let people =
new List<_>(
[|
{First = "Bhushan"; Last = "Shinde"}
{ First = "Abhi"; Last = "Jad"}
|])
It gives the error: No constructors are available for the type ‘List<‘a>’
Can someone please explain what is the problem?
Thank you.
In F#, the name
List<_>is used to refer to the immutable F# list (defined in F# core library).If you want to create mutable .NET list (
System.Collections.Generic.List<_>), you need to use an alias that is defined in the F# libraryResizeArray<_>(or you need to use fully qualified name):If you want to create a normal F# list (and use it in a functional style), then you can just use the list comprehension syntax without passing the value to any constructor: