OCaml option return 值和选项匹配
OCaml option return value and option matching
我想编写一个接受自定义 class myType
和 returns myType option
值的函数。不确定我的问题是签名、内容还是 return 值。
例如,我试着写了下面的(它是简化的,没有实际意义):
let rec myFunc (t:myType) myType option =
let t2 = myFunc t in
match t2 with
| None -> None
| _ -> t
我收到以下编译错误:
Error: This pattern matches values of type 'a option
but a pattern was expected which matches values of type 'b -> 'c -> 'd
不确定我的语法有什么问题或我误解了 OCaml。
我只看到一个冒号和 Some
:
let rec myFunc (t:myType): myType option =
let t2 = myFunc t in
match t2 with
| None -> None
| _ -> Some t
略微精简版:
let rec myFunc (t:myType): myType option =
match myFunc t with
| None -> None
| _ -> Some t
我想编写一个接受自定义 class myType
和 returns myType option
值的函数。不确定我的问题是签名、内容还是 return 值。
例如,我试着写了下面的(它是简化的,没有实际意义):
let rec myFunc (t:myType) myType option =
let t2 = myFunc t in
match t2 with
| None -> None
| _ -> t
我收到以下编译错误:
Error: This pattern matches values of type 'a option but a pattern was expected which matches values of type 'b -> 'c -> 'd
不确定我的语法有什么问题或我误解了 OCaml。
我只看到一个冒号和 Some
:
let rec myFunc (t:myType): myType option =
let t2 = myFunc t in
match t2 with
| None -> None
| _ -> Some t
略微精简版:
let rec myFunc (t:myType): myType option =
match myFunc t with
| None -> None
| _ -> Some t