caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Strange behavior of mutualy recursive definitions
@ 2011-04-27 20:46 rixed
  2011-04-27 20:54 ` Guillaume Yziquel
  0 siblings, 1 reply; 10+ messages in thread
From: rixed @ 2011-04-27 20:46 UTC (permalink / raw)
  To: caml-list

I met this strangeness today and would like to know is it a FAQ? Is it
intentional? Is it fixable?

# let inc f x = (f x)+1 and dec f x = (f x)-1;;
val inc : ('a -> int) -> 'a -> int = <fun>
val dec : ('a -> int) -> 'a -> int = <fun>
# let rec toto = inc titi and titi = dec toto;;
Error: This kind of expression is not allowed as right-hand side of `let rec'

Now after reading http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#s:letrecvalues ,
this is unclear why toto and titi definitions are not 'statistically constructive':
It seams that one could trivially add a "fun f -> ... f" around the
function bodies in order to comply with the rules. And actually, this
even simpler (but to my knowledge equivalent) definition works :

# let rec toto x = inc titi x and titi x = dec toto x;;
val toto : 'a -> int = <fun>
val titi : 'a -> int = <fun>

So why was the first version rejected?


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

end of thread, other threads:[~2011-04-28  8:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-27 20:46 [Caml-list] Strange behavior of mutualy recursive definitions rixed
2011-04-27 20:54 ` Guillaume Yziquel
2011-04-27 21:28   ` rixed
2011-04-27 21:51     ` Guillaume Yziquel
2011-04-28  4:05       ` rixed
2011-04-28  6:24         ` [Caml-list] " Jeffrey Scofield
2011-04-28  8:45           ` Guillaume Yziquel
2011-04-28  8:57             ` rixed
     [not found]       ` <244248468.756230.1303963610378.JavaMail.root@zmbs4.inria.fr>
2011-04-28  7:26         ` [Caml-list] " Fabrice Le Fessant
2011-04-28  8:53           ` rixed

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