Browse thread
Yet another question about insufficient polymorphism
-
Richard Jones
- Richard Jones
- Richard Jones
[
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: | 2008-03-18 (10:56) |
From: | Richard Jones <rich@a...> |
Subject: | Re: [Caml-list] Yet another question about insufficient polymorphism |
On Wed, Mar 12, 2008 at 07:34:32PM +0000, Richard Jones wrote: > I have a signature like this: > > newt.mli: > > type 'a component > > val form_add_component : > [> `Form ] component -> [> `Component ] component -> unit > val form_add_components : > [> `Form ] component -> [> `Component ] component list -> unit > > An implementation like this: > > newt.ml: > > type 'a component = { > co : newtComponent; > mutable in_form : bool; > } [...] > 04_form.ml: > > let text = textbox 1 1 15 5 [WRAP; SCROLL] in > textbox_set_text text "This is some text in a reflowed text box."; > let b1 = button 5 8 " OK " in > let b2 = button 5 13 "Cancel" in > let form = form None None [] in > form_add_components form [text; b1; b2]; > ^^ The answer to this, pointed out to me by milanst, is to write the type like this: type _component = { co : newtComponent; mutable in_form : bool; } type 'a component = _component which works as expected, without any "casts" needed on the call to form_add_components. Rich. -- Richard Jones Red Hat