本文介绍了ocaml类型不匹配单元与列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为此签名
val chooser: string list * string list -> string list和此实现
let rec chooser (inputList, trueList) = match inputList with [] -> [] | iH::iT -> if (List.hd trueList)="True" then iH::(chooser iT List.tl trueList)我收到以下错误:
错误:此变量表达式应具有类型单位 构造函数::不属于单位
Error: This variant expression is expected to have type unit The constructor :: does not belong to unit
我做错了什么?
推荐答案不包含else的if ... then的结果必须为unit,因为该值将为()(类型为)表达式为假时.
The result of if ... then with no else has to be unit, because the value will be () (the value of type unit) when the expression is false.
换句话说,您需要为if使用else部分来获取所需的类型.比较为假时,该值应该是什么?
In other words, you need an else part for your if to get the type you want. What should the value be when the comparison is false?
更多推荐
ocaml类型不匹配单元与列表
发布评论