繁体   English   中英

此F#代码不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM