English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] troubles with polymorphic variant in class
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-06-14 (09:29)
From: François-Xavier HOUARD <IdeFX@I...>
Subject: Re: [Caml-list] troubles with polymorphic variant in class
Le dim 13/06/2004 à 19:59, skaller a écrit :

> (* fixpoint *)
> type widget = 'w widget' as 'w 
> which effectively solves the type equation
> 'w = 'w widget (and names the result widget).
> Now define non-polymorphic classes:
> class button = [widget] button'
> class window = [widget] window'
> This is not so bad for a single parameter 'w.
> For multiple parameters the notation soon becomes
> too unwieldy to be practical. 

But the answer you gave me, which I find quite nice, don't allow my user
to add his own class....
I could do the stuff with a parametrized module (the parameter given by
the user would contain the variant used in the program... Including the
ones of my library!!), or, even uglier, use a close variant in my
module, which would be like:
[ Window of window | Frame of frame | User_variant of 'a ]

And 'a, the parameter of the module, given by the user, would also be a

module SillyModule =
	type t = [ MyWindow of myWindow | MyText of myText ];;
module myGui = Gui (SillyModule);;
let a = new Window;;
let x = new myText a;;
let l = a#get_child in
match l with
h::t -> (match h with 
	 	myGui.User_variant v ->
			( match v with
			    MyText t -> .......
			    | _ ->
		| _ -> raise Not_found

Who the hell would use this ??? 

So, if I can't find a better solution, i could still try to find a
sado-m(l)asochist mailing list, to find potential users !


Let's be more serious. What you said is fine, but, please, tell me there
is an easier solution to make it work with user defined class...

Thanks for all

FX Houard, desperate to find an elegant and extensible solution to his
problem... And attracted by the dark-dynamic-typed side of coca-ml.

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners