From: Guillaume Yziquel <guillaume.yziquel@citycable.ch>
To: rixed@happyleptic.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Strange behavior of mutualy recursive definitions
Date: Wed, 27 Apr 2011 22:54:16 +0200 [thread overview]
Message-ID: <20110427205416.GL4023@localhost> (raw)
In-Reply-To: <20110427204629.GA8872@yeeloong.happyleptic.org>
Le Wednesday 27 Apr 2011 à 22:46:29 (+0200), rixed@happyleptic.org a écrit :
> 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?
Because to evaluate toto, you need to have titi evaluated beforehand
(wouldn't be the case if you had 'let rec toto = titi inc' instead of
'inc titi', typically). And to evaluate titi, you need to have evaluated
beforehand the value toto.
The second version only defines toto as a function that calls titi. No
need to have titi evaluated to be able to evalue toto. You only need to
know where it is declared. That's the main difference.
--
Guillaume Yziquel
next prev parent reply other threads:[~2011-04-27 20:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 20:46 rixed
2011-04-27 20:54 ` Guillaume Yziquel [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110427205416.GL4023@localhost \
--to=guillaume.yziquel@citycable.ch \
--cc=caml-list@inria.fr \
--cc=rixed@happyleptic.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox