[Haskell-cafe] Re: Composition of Type Constructors

Jan Christiansen jac at informatik.uni-kiel.de
Mon May 30 09:26:52 EDT 2005


On Wednesday 25 May 2005 17:20, Chung-chieh Shan wrote:
> Jan Christiansen <jac at informatik.uni-kiel.de> wrote in article <Pine.GSO.4.63.0505251243020.11488 at arwen> in gmane.comp.lang.haskell.cafe:
>> The problem is that I don't know how to express the composition of
>> type constructors like the function (.) for ordinary functions. I know
>> that (map1 . map2) is wrong but it states what I want to express,
>> namely the composition of two type constructors. With this I would
>> like to define an instance definition like the following.
>>
>>
>> instance (Mapping map1 key1, Mapping map2 key2)
>>        => Mapping (map1 . map2) (key1, key2) where
>>    lookup (key1, key2) = lookup key2 . lookup key1
>>    update (key1, key2) f = update key1 (update key2 f)
>
> You can define the type-level composition yourself.  Something like
> (untested):
>
> newtype Comp map1 map2 v = Comp (map1 (map2 v))
> instance (Mapping map1 key1, Mapping map2 key2)
>        => Mapping (Comp map1 map2) (key1, key2) where
>     lookup (key1, key2) (Comp map) = lookup key2 (lookup key1 map)
>     update (key1, key2) f (Comp map) = Comp (update key1 (update key2 f)
> map)

Thanks. That's a solution. There is no prettier way of doing this, is there.

It's not allowed to make an instance of a type synonym and partially 
applied type synonyms are not allowed anyway. Is there a reason why 
partial application of type synonyms are forbidden?


More information about the Haskell-Cafe mailing list