f# interactive - f# Seq of tuple item1 -


i don't understand why i'm getting error below:

> let x = "abcdaaccecfg"|>seq.sort|>seq.groupby (fun x->x);; val x : seq<char * seq<char>>  > x;; val : seq<char * seq<char>> =   seq     [('a', seq ['a'; 'a'; 'a']); ('b', seq ['b']);      ('c', seq ['c'; 'c'; 'c'; 'c']); ('d', seq ['d']); ...]  > (x|> seq.head).gettype();; val : system.type =   system.tuple`2[system.char,system.collections.generic.ienumerable`1[system.char]]     {assembly = mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089;      assemblyqualifiedname = "system.tuple`2[[system.char, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089],[system.collections.generic.ienumerable`1[[system.char, mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089]], mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089]], mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"; ...      declaredproperties = [|char item1;                             system.collections.generic.ienumerable`1[system.char] item2;                             int32 system.ituple.size|]; ...;}  > x|> seq.map (fun x -> x.item1, x.item2)|>dict;;    x|> seq.map (fun x -> x.item1, x.item2)|>dict;;   ------------------------^^^^^  stdin(123,25): error fs0039: field, constructor or member 'item1' not defined. 

it appears me x sequence of tuples each tuple has item1 (char) , item2 (seq char) property. i'd turn dictionary.

clearly, i'm missing something. can me understand i'm doing wrong , how right?

it doesn't appear f# surfaces item1 , item2 properties underlying tuple in c#. tried following appear work without error.

using functions fst , snd:

x|> seq.map (fun x -> fst x, snd x) |> dict 

using pattern matching:

x|> seq.map (function (key, value) -> (key, value)) |> dict 

and apparently without using seq.map works well:

x |> dict 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -