Version franēaise
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2008-02-27 (23:32)
From: Loup Vaillant <loup.vaillant@g...>
Subject: Re: [Caml-list] Unexpected restriction in "let rec" expressions
2008/2/27, Dirk Thierbach <>:
> On Wed, Feb 27, 2008 at 03:04:03PM +0100, Loup Vaillant wrote:
>  > Yes, it does, but I have difficulties reducing this expression.
> Where is the problem?

After reducing the call to loop and inlining f in the resulting
expression, I couldn't reduce the recursive let anymore. I thought of
replacing the let by a lambda expression, but since it is recursive,
it can't be done (or at least it's not trivial). But this is not a
problem anymore.

>  > Do you have another example which can be reduced to head normal form
>  > (say the result is an int instead of a list)?
> Not with ground types, but would the factorial function help?
>  f (x,g) = (g x, g') where
>   g' 0 = 1
>   g' y = y * g (y-1)
>  *Main> [loop f x | x <- [0..10]]
>  [1,1,2,6,24,120,720,5040,40320,362880,3628800]

Cool, this is exactly what I wanted, thanks.

>  BTW, lazy evaluation uses weak head normal form (WHNF), not head normal
>  form.

This is precisely why I wanted the result type to be such that
WHNF=>HNF. Int is such a type. List is not.