[英]This F# code is not working
這不起作用...我收到錯誤FS0001:類型'string'與最后一行的類型'seq'不兼容。 為什么?
let rec Parse (charlist) =
match charlist with
| head :: tail -> printf "%s " head
Parse tail
| [] -> None
Parse (Seq.toList "this is a sentence.") |> ignore
問題是printf "%s " head
表示head
必須是一個string
,但實際上您希望它是一個char
,因此您將看到Parse
推斷出了類型string list -> 'a option
。 因此,F#希望將Seq.toList
應用於string seq
,而不是string
。
簡單的解決方法是將打印行更改為printf "%c " head
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.