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: Gabriel Kerneis <kerneis@e...>
Subject: Re: [Caml-list] Unexpected restriction in "let rec" expressions
Le Tue, 26 Feb 2008 15:34:37 +0100, "Loup Vaillant"
<loup.vaillant@gmail.com> a écrit :
> # let loop f a =
>     let rec couple () = f (a, snd (couple ())) in
>       fst (couple ());;
>     val loop : ('a * 'b -> 'c * 'b) -> 'a -> 'c = <fun>
> 
> Now, I have yet to figure out the purpose of this so called "fixpoint
> operator" (and if the above will work at all :-).

No, it won't:
Objective Caml version 3.10.1
# let loop f a =
    let rec couple () = f (a, snd (couple ())) in
      fst (couple ());;
    val loop : ('a * 'b -> 'c * 'b) -> 'a -> 'c = <fun>
# loop (fun x -> x) 1 ;;
Stack overflow during evaluation (looping recursion?).

Whereas:

GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> :load test
[1 of 1] Compiling Main             ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main> loop id 1
1

You could (maybe) get it using the Lazy module.

Regards,
-- 
Gabriel Kerneis