Browse thread
Polymorphic recursion
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-04-03 (20:00) |
From: | brogoff <brogoff@s...> |
Subject: | Re: [Caml-list] Polymorphic recursion |
On Tue, 3 Apr 2007, Till Varoquaux wrote: > Therefor, if you wish to use polymorphic recursion (yep you can) you > might want to use something where you have to specify the type; this > includes records, objects and recursive modules. So this > > type 'a seq = Unit | Seq of ('a * ('a * 'a)seq) > > type szRec={f:'a.'a seq -> int};; > > let size= > let rec s = > {f=function > | Unit -> 0 > | Seq(_, b) -> 1 + 2 * s.f b} > in > s.f > > might be what you where yearning for. What I'd be yearning for would be more like let rec size : 'a . 'a seq -> int = fun s -> match s with Unit -> 0 | Seq(_,b) -> 1 + 2 * (size b) rather than having to use recursive modules or higher rank polymorphism of record fields/polymorphic methods. -- Brian