OCaml - 警告 8:此模式匹配并不详尽
OCaml - Warning 8: this pattern-matching is not exhaustive
你好,我有这个程序工作得很好,但给了我一个警告,我想摆脱它
let rec replace_helper (x::xs) n acc =
if n = 0 then
List.rev acc @ symbol :: xs
else
replace_helper xs (pred n) (x :: acc)
in
replace_helper tape position []
;;
这是警告
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:[]
我该怎么做才能摆脱这个
您的 x::xs
模式只能匹配一个非空列表(而您忘记处理空列表的情况 []
)。请完成以下代码
let rec replace_helper li n acc = match li with
[] -> (*code something here*) failwith "incomplete"
| x::xs ->
if n = 0 then
List.rev acc @ symbol :: xs
else
replace_helper xs (pred n) (x :: acc)
in
replace_helper tape position []
;;
当然还有阅读更多内容http://ocaml.org/
你好,我有这个程序工作得很好,但给了我一个警告,我想摆脱它
let rec replace_helper (x::xs) n acc =
if n = 0 then
List.rev acc @ symbol :: xs
else
replace_helper xs (pred n) (x :: acc)
in
replace_helper tape position []
;;
这是警告
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:[]
我该怎么做才能摆脱这个
您的 x::xs
模式只能匹配一个非空列表(而您忘记处理空列表的情况 []
)。请完成以下代码
let rec replace_helper li n acc = match li with
[] -> (*code something here*) failwith "incomplete"
| x::xs ->
if n = 0 then
List.rev acc @ symbol :: xs
else
replace_helper xs (pred n) (x :: acc)
in
replace_helper tape position []
;;
当然还有阅读更多内容http://ocaml.org/