I am porting some Haskell code to F #, but I'm a bit confused about the collections available and their signatures in F #. I understand that elements in lists are enclosed between [], sequences between {} and arrays between [| |]. In F # Interactive, I get the following when I create each container with 5 int.
// List > [1..5] val it : int list = [1; 2; 3; 4; 5] // Seq > {1..5} val it : seq<int> = seq [1; 2; 3; 4; ...] // Array > [|1..5|] val it : int [] = [|1; 2; 3; 4; 5|]
What bothers me is that the type signature for arrays is int [] . Maybe the type int array or int [||] will be less confusing? If you look at the type signature, I tend to think that this is a list, especially because an empty list is also represented as [].
One question here: why is the sequence type seq<int> and not int seq . I suppose it might be syntactic sugar, but maybe there is something else behind it.
Now create new types using the collection:
type T1 = T1 of int list type T2 = T2 of int seq // becomes type T2 = T2 of seq<int> type T3 = T3 of int array type T4 = T4 of int []
Are T3 and T4 the same?
source share