Browse thread
Yet another question about insufficient polymorphism
- 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-12 (19:34) |
From: | Richard Jones <rich@a...> |
Subject: | Yet another question about insufficient polymorphism |
This is yet another "insufficient polymorphism" question that I just can't work out ... 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; } let form_add_component form co = if co.in_form then failwith "component can only be added to a single form"; newtFormAddComponent form.co co.co; co.in_form <- true let form_add_components form components = List.iter (fun co -> form_add_component form co) components And my test program is: 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]; ^^ File "examples/04_form.ml", line 17, characters 33-35: This expression has type [ `Button | `Component ] Newt.component but is here used with type [ `Component | `Textbox ] Newt.component The second variant type does not allow tag(s) `Button make: *** [examples/04_form.cmo] Error 2 This all worked until I added the newt.mli file. (I previously just had a newt.ml file, with explicit types on all the functions). Rich. -- Richard Jones Red Hat