English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2009-10-22 (22:22)
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"

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
	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.