Version française
Home     About     Download     Resources     Contact us    
Browse thread
forbidden construct as right hand side of "let rec"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mathias Kende <mathias@k...>
Subject: forbidden construct as right hand side of "let rec"
Hello list,

I need to write something like this :

	let f f i = if i = 0 then 1 else i * f (i - 1)
	let rec g = f g

Of course the compiler won't let me write it (even if the OCaml type
system is happy):
	"This kind of expression is not allowed as right-hand side of `let rec'"

But as the function parameter of function f is used only for a recursive
call I believe that the function I try the define is at least "morally"
correct.

Is there a way to express this sort of construction in OCaml ? My aim is
to be able to have some things equivalent to:
	let rec g = f g
and
	let rec h = t (f h)
where t is some transformation over the function (conserving its type),
and still writing the code for f only once.

Regards,

Mathias