On Wed, 8 Jan 2003 07:19 am, Hal Daume III wrote:
> Another way to do it would be to define a "universal" type:
> > data Univ = UUnit () | UInteger Integer | UDouble Double | ...
>

I'm fairly new to Haskell, but worked on Mercury until recently.
Mercury has a type "univ" which might be declared something like:

data Univ = Univ a

(I don't know the correct syntax for existentially quantified types in 
haskell, but the intent of the declaration is that the monomorphic type Univ 
has a single constructor is a value of existentially quantified type)

The library then has functions that do the equivalent of

mkUniv :: a -> Univ

and

getValue :: Univ -> Maybe a

The interesting bit is getValue. In implementation terms, what it does is
compare the dictionary stored in the Univ value (values containing 
existentially quantified components also contain the dictionary for the 
existentially quantified type variables) with the one that is implicitly 
passed in for the result type.  As it happens, almost all of this can be
done in Mercury using some of the reflection libraries.

I believe (nth hand) that something similar has been done in haskell, but my 
understanding is that it isn't in the standard library.

Tom
-- 
    Dr Thomas Conway      Multimedia Database Systems, RMIT University
 <[EMAIL PROTECTED]> 499 User error! Replace user, and press any key.
_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to