> The *only* way I have been able to make this work, after lots of
> trying and mind-bending, is to introduce a "phantom" type to allow me
> to combine things appropriately:
> 
> > data MkFinMap m k a = MkFinMap (m (Pair k a))
> 
> > instance (SortedList m (Pair k a), ZeroVal a) => 
> >          FiniteMap (MkFinMap m) k a where
> >   emptyMap = MkFinMap emptySort
> >   bindMap (MkFinMap t) k x = MkFinMap (addToSort t (Pair k x))
> >   lookupMap (MkFinMap t) k =
> >      let r = findInSort t (Pair k zer) 
> >      in case r of
> >         Nothing          -> Nothing
> >         Just (Pair k' x) -> Just x

I don't think you can avoid this. You have two type constructors:

        class SortedList s a where ...
        class FiniteMap m k a where ...

        s has kind *->*
        m has kind *->*->*

You want to say

        instance SortedList s (Pair k a) => FiniteMap m k a where...

but there's a relationship between s and m, namely

        m k a = s (Pair k a)

That is the relationship your MkFinMap states.  

I don't know how to improve on this... except to give sortedList a 
key and a value.

You don't need class ZeroVal.. just use 'undefined' instead.

Simon


Reply via email to