Version franēaise
Home     About     Download     Resources     Contact us    
Browse thread
Unexpected restriction in "let rec" expressions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe_Filliātre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] Unexpected restriction in "let rec" expressions
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