Is it possible to match with decomposed sequences in F#?
Posted
by Ball
on Stack Overflow
See other posts from Stack Overflow
or by Ball
Published on 2009-11-17T15:17:35Z
Indexed on
2010/06/11
19:53 UTC
Read the original article
Hit count: 248
I seem to remember an older version of F# allowing structural decomposition when matching sequences just like lists. Is there a way to use the list syntax while keeping the sequence lazy? I'm hoping to avoid a lot of calls to Seq.head and Seq.skip 1.
I'm hoping for something like:
let decomposable (xs:seq<'a>) =
match xs with
| h :: t -> true
| _ -> false
seq{ 1..100 } |> decomposable
But this only handles lists and gives a type error when using sequences. When using List.of_seq, it seems to evaluate all the elements in the sequence, even if it is infinite.
© Stack Overflow or respective owner