Browse thread
Structural subtyping problem
-
Dario Teixeira
- Vincent Aravantinos
- Andreas Rossberg
-
Stéphane Glondu
- Christophe TROESTLER
- Dario Teixeira
[
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: | 2010-03-28 (19:20) |
From: | Christophe TROESTLER <Christophe.Troestler+ocaml@u...> |
Subject: | Re: [Caml-list] Structural subtyping problem |
Hi, On Sun, 28 Mar 2010 19:32:37 +0200, Stéphane Glondu wrote: > > type steps = { > step1 : 'a. ?story:(<title : string; ..> as 'a) -> unit -> bool; > step2 : string -> bool; > step3 : 'a. story:(<title : string; count : int; ..> as 'a) -> bool > } > > let rec steps = { [...] IMHO, recursive modules are also a nice way to achieve the same effect : module rec X : sig val step1 : ?story:<title : string; ..> -> unit -> bool val step2 : string -> bool val step3 : story:<title : string; count : int; ..> -> bool end = struct let rec step1 ?story () = match story with | Some s -> X.step2 s#title | None -> X.step2 "title1" and step2 title = let story = object method title = title method count = 0 end in X.step3 story and step3 ~story = match story#count with | 0 -> X.step1 ~story () | 1 -> let story = object method title = "title2" end in X.step1 ~story () | _ -> true end My 0.02¤, C.