Ocaml 递归函数与";“让进来”;错误
我试图弄清楚这个函数的作用,当我在代码编辑器中运行它时,它在“end in”处给了我一个语法错误。我试着在“let x”和其他一些地方加上括号,但我不知所措。如果您能帮助我理解为什么会出现错误,我将不胜感激Ocaml 递归函数与";“让进来”;错误,ocaml,Ocaml,我试图弄清楚这个函数的作用,当我在代码编辑器中运行它时,它在“end in”处给了我一个语法错误。我试着在“let x”和其他一些地方加上括号,但我不知所措。如果您能帮助我理解为什么会出现错误,我将不胜感激 let rec map (f: 'a -> 'b) (y: 'a list): 'b list = begin match y with | [] -> [] | h :: t -> (f h) :: (map f t) end in let x = ma
let rec map (f: 'a -> 'b) (y: 'a list): 'b list =
begin match y with
| [] -> []
| h :: t -> (f h) :: (map f t)
end in
let x = map (fun t -> (t + 1) [0; 1; 2] in
0 :: x
这就是你想要实现的吗
let () =
let rec map f y =
match y with
| [] -> []
| h :: t -> (f h) :: (map f t)
in
let x = map (fun t -> t + 1) [0; 1; 2] in
0 :: x
|> List.iter (fun x -> Printf.printf "%d\n" x)
检查你的父母,这是不平衡的。