【发布时间】:2019-03-04 09:06:50
【问题描述】:
我有这个代码:
let n = read_int()
let rec fact n = if n=0 then 1 else n*fact(n-1)
let () = Printf.printf "%d factorial is %d.\n" n fact(n)
我编译然后编译器说:
File "fat.ml", line 3, characters 23-46:
Error: This expression has type
('a -> 'b, out_channel, unit, unit, unit, 'a -> 'b)
CamlinternalFormatBasics.fmt
but an expression was expected of type
('a -> 'b, out_channel, unit, unit, unit, unit)
CamlinternalFormatBasics.fmt
Type 'a -> 'b is not compatible with type unit
如何打印返回值?
【问题讨论】:
标签: function recursion ocaml factorial