您好,我有这个程序正常工作,但给我一个警告,我想摆脱
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:[]我能做些什么来摆脱这个?
发布于 2021-01-03 02:52:39
您的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/
https://stackoverflow.com/questions/65542825
复制相似问题