On 22-Nov-1999, Alex Ferguson <[EMAIL PROTECTED]> wrote:
> 
> Here's some of the threatened examples:
> 
> > data OrdFuncExist = OE (Ord a => Char -> a)
> 
That's not the syntax for a existential type,
that's the syntax for a universally quantified type
with rank-2 polymorphism.  With that syntax, the
argument of `OE' must be a polymorphic function
with type `forall a . Ord a => Char -> a'.

I think the syntax for what you want is
        data OrdFuncExist = Ord a => OE (Char -> a)

> > data OrdListExist = OLE (Ord a => [a])

Is this supposed to be a heterogenous list,
or a homogeneous list?  That is, must the elements
all have the same type `a', or is the choice of `a' 
supposed to be allowed to vary for each element?

If you want a homogeneous existentially quantified list,
then use

        data OrdListExist = Ord a => OLE [a]

But I suspect you want a heterogenous existentially quantified list.
In that case, you should use something like this:

        data AnyOrd = Ord a => MkAnyOrd a
        data OrdListExist = [AnyOrd]

> > emap :: OrdFuncExist -> [Char] -> OrdListExist
> > emap (OE f) l = OLE (map f l)

You'll probably need something along the lines of

        emap (OE f) l = OLE (map (MkAnyOrd . f) l)

> The other problem:
> 
> > emax :: OrdListExist -> OrdListExist
> > emax (OLE l) = OLE [maximum l]
> 
> Now, I think I see why this doesn't work:  but any ideas on how to fix?

Hmm, I'm not sure exactly what you're trying to achieve here...
but perhaps you just need to add
        
        instance Ord AnyOrd where
                compare (MkAnyOrd x) (MkAnyOrd y) = compare x y

to make it work.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to