caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jean-Christophe Filliâtre" <Jean-Christophe.Filliatre@lri.fr>
To: Loup Vaillant <loup.vaillant@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Unexpected restriction in "let rec" expressions
Date: Tue, 26 Feb 2008 15:04:44 +0100	[thread overview]
Message-ID: <47C41C7C.6010006@lri.fr> (raw)
In-Reply-To: <6f9f8f4a0802260424o5bce2fd9i89fbfa38bb239a6a@mail.gmail.com>

Loup Vaillant a écrit :
> I was trying to translate this simple Haskell definition in Ocaml:
> 
> loop :: ((a,c) -> (b,c)) -> a -> b
> loop f a = b
>   where (b,c) = f (a,c)
> 
> However, the direct translation doesn't work:
> 
> # let loop f a =
>   let rec (b, c) = f (a, c) in
>     b;;
>     Characters 25-31:
>     let rec (b, c) = f (a, c) in
>             ^^^^^^
> Only variables are allowed as left-hand side of `let rec'
> 
> So I try to bypass this restriction:
> 
> # let loop f a =
>   let rec couple = f (a, snd couple) in
>     fst couple;;
>     Characters 34-51:
>     let rec couple = f (a, snd couple) in
>                      ^^^^^^^^^^^^^^^^^
> This kind of expression is not allowed as right-hand side of `let rec'
> 
> 
> Any ideas about what is this restriction, an what is it for?

Ocaml has call-by-value, and it cannot figure out a value to be passed
as f's second argument. To be convinced, just imagine that the type of
this argument is empty (an empty type can be introduced by "type empty"
without definition, for instance).

-- 
Jean-Christophe


  reply	other threads:[~2008-02-26 14:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-26 12:24 Loup Vaillant
2008-02-26 14:04 ` Jean-Christophe Filliâtre [this message]
2008-02-26 14:18 ` [Caml-list] " Damien Doligez
2008-02-26 14:34   ` Loup Vaillant
2008-02-26 14:51     ` Gabriel Kerneis
2008-02-26 14:56     ` blue storm
2008-02-26 17:48     ` Nicolas Pouillard
2008-02-26 14:57 ` Dirk Thierbach
2008-02-27  8:53 ` Andrej Bauer
2008-02-27  9:43   ` Loup Vaillant
2008-02-27 12:02     ` Dirk Thierbach
2008-02-27 14:04       ` Loup Vaillant
2008-02-27 16:41         ` Dirk Thierbach
2008-02-27 23:32           ` Loup Vaillant
2008-02-27 19:03 ` Pal-Kristian Engstad
2008-02-27 23:46   ` Loup Vaillant

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=47C41C7C.6010006@lri.fr \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@inria.fr \
    --cc=loup.vaillant@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).