> Ok, I did not reconize this solution, it seems to me the (nearly) proper one.
> But why not write:
>
> class => Dictionary dict where
> delete :: (Eq key, Ord key) => key -> dict key dat -> dict key dat
> ...
>
> So one could avoid multiparamter classes at all. The two types key and dat
> should be inferred by the type of dict (which is expressed by 'dict key dat'). I
> can't think about a dictionary where key or dat are not associated with dict.
That's the usual approach taken with single parameter type classes.
However, not every implementation for finite maps (the functional
programmer's term for dictionary) works for all element types. Think of
tries or general tries (see Okasaki's book `Purely functional data
structures', p. 163-169). Or else we could have a different restriction
on the element types, eg (Hashable key) instead of (Ord key) for hash
based implementations. That said the following declarations seems
appropriate (cf PFDS, p. 204):
class FiniteMap map k where
empty :: map k a
insert :: k -> a -> map k a -> map k a
delete :: k -> map k a -> map k a
instance (Ord k) => FiniteMap SplayTree k where
instance (Hashable k) => FiniteMap HashTable k where
Ad-hoc tries:
instance FiniteMap Trie [k] where
Tries where the mapping from edge labels to tries is parametrised:
instance (FiniteMap m k) => FiniteMap (Trie m) [k] where
Cheers, Ralf