0
votes

This is not working... I get error FS0001: The type 'string' is not compatible with the type 'seq' for the last line. Why?

let rec Parse (charlist) =
   match charlist with
   | head :: tail -> printf "%s " head
                     Parse tail
   | [] -> None

Parse (Seq.toList "this is a sentence.") |> ignore
1
Seq operates on a sequence and string isn't a sequence. - Lazarus
can someone please "Edit" the Title of that question..to make it easier. thx - bastianneu
@Lazarus - string is a sequence, but it's a sequence of chars where the inferred type of Parse requires a sequence of strings. - kvb

1 Answers

2
votes

The problem is that printf "%s " head means that head must be a string, but you actually want it to be a char, so you'll see that Parse has inferred type string list -> 'a option. Therefore, F# expects Seq.toList to be applied to a string seq, not a string.

The simple fix is to change the line doing the printing to printf "%c " head.