caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* forbidden construct as right hand side of "let rec"
@ 2009-10-22 22:22 Mathias Kende
  2009-10-22 22:34 ` [Caml-list] " Stéphane Glondu
  2009-10-28 16:52 ` Xavier Leroy
  0 siblings, 2 replies; 10+ messages in thread
From: Mathias Kende @ 2009-10-22 22:22 UTC (permalink / raw)
  To: caml-list

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




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-10-28 22:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22 22:22 forbidden construct as right hand side of "let rec" Mathias Kende
2009-10-22 22:34 ` [Caml-list] " Stéphane Glondu
2009-10-22 23:10   ` Lukasz Stafiniak
2009-10-23 15:35     ` Damien Guichard
2009-10-23 16:14       ` Marc de Falco
2009-10-23 17:51         ` blue storm
2009-10-25 14:11   ` Mathias Kende
2009-10-25 15:03     ` Stéphane Glondu
2009-10-28 16:52 ` Xavier Leroy
2009-10-28 22:44   ` Lukasz Stafiniak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).