Automatic coercition to a more general type ?

Christian Boos (boos@gr6.u-strasbg.fr)
Wed, 19 Jun 96 13:12:36 +0200

Date: Wed, 19 Jun 96 13:12:36 +0200
From: boos@gr6.u-strasbg.fr (Christian Boos)
Message-Id: <9606191112.AA11535@gr6.u-strasbg.fr>
To: caml-list@pauillac.inria.fr
Subject: Automatic coercition to a more general type ?

Bonjour,

J'ai une question concernant le sous-typage et la nécessité de faire
une coercition explicite d'un objet en un type plus général (par
exemple pour mettre des objets de classes différentes dans une même
liste, en forçant un type 'ancêtre commun', cf. exemple point et color_point
de la doc).

N'y aurait-t-il pas moyen de réaliser cette coercition de façon
automatique en trouvant le type intersection des types de ces objets ?

L'unification de deux types de classes différent consisterait à
trouver leur type intersection, et à ne renvoyer une erreur que si un
tel type n'existe pas. En cas de succès, le type unifié est bien
entendu ce type intersection.

Je ne sais pas si cela poserait des problèmes d'ordre théorique.

------

Hello,

I have a question about subtyping, and the need to explicitly coerce
the type of an object to be of a more general type, when needed.
I wonder if it is possible to do this coercition automatically. When
unifying a type 'class_a' with a type 'class_b', the typechecker tries
to find a new type 'class_c' which is the intersection of 'class_a'
and 'class_b'. If this is successfull, then the resulting type would
be 'class_c', if not, the unification would fail.

Perhaps there's theoretical weakness to this proposal ?

-- Christian