我有以下代码。我将返回类型明确定义为boolean
let inputChecker (romanNumber:list<char>) :bool = function
| [] -> false
| head::tail when head<= tail.Head && tail.Head<=tail.Tail.Head -> false
| _ -> true
但我认为它认为:bool
是一个参数。我也尝试过(:bool)
,但仍然无法正常工作。
如果使用function
,则不要在签名中指定参数:
let inputChecker: (char list -> bool) = function
| [] -> false
| head::tail when head<= tail.Head && tail.Head<=tail.Tail.Head -> false
| _ -> true
如果要显式指定参数,请使用 match
let inputChecker (romanNumber: char list): bool =
match romanNumber with
| [] -> false
| head::tail when head<= tail.Head && tail.Head<=tail.Tail.Head -> false
| _ -> true
类型注释不是必需的,您可以跳过它们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句