Tree insert, lookup with keys

Ketil Z. Malde
20 Dec 2002 11:16:19 +0100

Ingo Wechsung <> writes:

> class Keyed a where {		-- Type a is keyed if it has a key function.
> 	key :: Ord b => a -> b;	-- key is a function, that, when applied to
> a yields some b that is comparable
> }

But it isn't obvious what b is supposed to be.  Try multi-parameter
type classes e.g.

class (Ord b) => Keyed a b where
        key :: a -> b

(I'm possibly messing up the placement of the 'Ord b' qualifier)

> and then

> data Sym  = Sym String Int Ty;		-- Ty  is another algebraic type
instance Keyed Sym String where
 	key (Sym a _ _) = a

(Requires -fglasgow-exts)

If I haven't seen further, it is by standing in the footprints of giants