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: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] The need to specify 'rec' in a recursive function defintion
On 2/10/2010 1:07 AM, Guillaume Yziquel wrote:
> Is it possible to have polymorphic recursion with vanilla 'let rec'
> invocations?

This is something that Jacques recently merged in the current 
development branch. The code below should work with OCaml 3.12.

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


-- Alain