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
Polymorphic recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-04-04 (15:17)
From: Alain Frisch <Alain.Frisch@i...>
Subject: Re: [Caml-list] Polymorphic recursion
Roland Zumkeller wrote:
> On 03/04/07, Loup Vaillant <> wrote:
>> Can't we implement non uniform recursive function (efficiently, or at
>> all)?.
> It has actually been done: call ocaml with the option "-rectypes" and
> your example will work as is.

No. The example would typecheck and the following type will be inferred:

  val size : ('a * 'a as 'a) seq -> int = <fun>

but since there is no value of type ('a * 'a as 'a) (for some 'a), you
will be able to apply the function only to the value Unit:

# size Unit;;
- : int = 0
# size (Seq (1, Unit));;
This expression has type int * 'a seq but is here used with type
  ('b * 'b as 'b) * ('b * 'b) seq

This is a good illustration of why -rectypes is not enabled by default.

-- Alain