我想执行此代码,但是我有这个错误。 OCaml中是否存在相互递归?
错误:未绑定的值quicksort您的意思是tquicksort吗?
我的问题:
let rec tquicksort lm l lM =
match l with
| [] -> unirL(unir (rev lm) lM)
| lx::lxs -> let (la, lb) = part lx lxs in
if nroelem la < nroelem lb then
tquicksort (quicksort (la::lm)) lb lM
else
tquicksort lm la (quicksort (lb::lM));;
let quicksort l = tquicksort [] l [];;
答案 0 :(得分:5)
您要求提供前向声明以允许相互递归。在OCaml中使用此方法的方法是使用let rec ... and ...
。
例如:
let rec g x = if x < 2 then x else f x
and f x = g (x - 1)