【发布时间】:2018-07-23 16:14:10
【问题描述】:
let rec smallest l =
match l with
| [] -> raise Not_found
| [a] -> (fun x -> if x > 0 then x else raise Not_found) a
| h::b::t ->
if h > b then smallest h::t
else smallest b::t`
如果列表中有一个正整数,该函数假定采用int list 并返回最小的int,如果列表中没有正整数,则引发异常Not_found。
当我尝试这个时,我收到以下错误,smallest h::t 在下划线的第三个匹配模式中找到:
错误:此表达式的类型为
'a list但应使用int类型的表达式
有人可以向我解释我做错了什么吗?
【问题讨论】:
标签: exception types error-handling pattern-matching ocaml