[TYPES] union types and overloading
Jacques Garrigue
garrigue at kurims.kyoto-u.ac.jp
Mon Oct 4 15:51:21 EDT 2004
From: Kwangkeun Yi <kwang at ropas.snu.ac.kr>
> I would like to extend our ML compiler's type system so that it allow
> functions to be defined over the sum of multiple datatypes. (union types?)
>
> E.g.,
>
> type t1 = A of int | B of t1
> type t2 = C | D of t2
>
> (* accept-both : t1+t2 -> int *)
> fun accept-both (A n) = n
> | accept-both (B x) = 0
> | accept-both C = 0
> | accept-both (D y) = 0
>
> Could you point me to some papers that I have to check out to avoid
> reinvention or to expect possible obstacles?
Well, polymorphic variants in Objective Caml allow you to do that.
You can find several papers about them on my publication page:
http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/papers/
"Programming with polymorphic variants" gives a good idea of the
feature and how to compile it, and "Simple type inference for
structural polymorphism" explains in detail how one can type them.
Seeing your above example, it seems that you have different ideas
about the typing, but the compilation technique may still be
interesting.
Hope this helps,
---------------------------------------------------------------------------
Jacques Garrigue Nagoya University garrigue at math.nagoya-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
More information about the Types-list
mailing list