[Haskell-cafe] Partially applied type synonyms in instance heads

Mathieu Boespflug mboes at tweag.net
Sat Oct 28 19:12:10 EDT 2006


Hi everyone,

I'm running into trouble with type synonyms in instance heads and I
can't figure out what the resulting error message means. The case I'm
considering is as follows:

-- hoist a and b to class variables so that instances declarations may
-- constrain them.
class Map m a b where
    toAssoc :: m a b -> [(a, b)]
    fromAssoc :: [(a, b)] -> m a b

type Assoc a b = [(a, b)]

instance Map Assoc a b where
    toAssoc = id
    fromAssoc = id

The class Map is used to allow translation from one map type to
another (FiniteMap, arrays, etc...) by means of expressing the map as
an association list. Useful for defining isomorphisms and so on. Now
I'd like to define an association list as itself a trivial instance of
Map class, but I cannot do so without wrapping the type of an
association list, [(a, b)], behind a type synonym, as I'm not aware of
any way of writing a type constructor of kind (* -> * -> *)
constructing the type [(a, b)].
But when compiling the above code with GHC I get the following error:

Map.hs:9:0:
    Type synonym `Assoc' should have 2 arguments, but has been given 0
    In the instance declaration for `Map Assoc a b'

Any idea what this means? Also, is there any other way of declaring an
instance for [(a, b)] without using type synonyms?

Many thanks,

Mathieu


More information about the Haskell-Cafe mailing list