Version française
Home     About     Download     Resources     Contact us    
Browse thread
The need to specify 'rec' in a recursive function defintion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Guillaume Yziquel <guillaume.yziquel@c...>
Subject: Re: [Caml-list] The need to specify 'rec' in a recursive function defintion
Gerd Stolpmann a écrit :
> Am Dienstag, den 09.02.2010, 22:58 +0100 schrieb Guillaume Yziquel:
>> Gerd Stolpmann a écrit :
>>> Am Dienstag, den 09.02.2010, 15:50 -0500 schrieb Saptarshi Guha:
>>>
>>> Besides the different way of defining "let" and "let rec" there are also
>>> differences in typing.
> 
> Well, at least you can have new effects. Look for "polymorphic
> recursion".

You mean something like this?

http://alaska-kamtchatka.blogspot.com/2009/05/polymorphic-recursion.html

With the following code

> type length = { length : 'a . int -> 'a vec -> int }
> 
> let length v =
>   let rec f = { length = fun n l -> match l with
>     Nil         -> n
>   | Zero    ps  -> f.length (    2 * n) ps
>   | One (_, ps) -> f.length (1 + 2 * n) ps
>   } in f.length 0 v

you get to use a function, here f.length, in two different contexts for 
type inference, allowing it to be used with multiple types? 'a * 'a 
instead of 'a? Am I getting this post right?

But then, this seems to go into rather elaborate constructions 
(existential types with OCaml records), which are quite remote from the 
simple 'let rec' issue we were talking about.

Is it possible to have polymorphic recursion with vanilla 'let rec' 
invocations? Or am I getting you wrong?

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/