[Haskell-cafe] Records and associated types

Taru Karttunen taruti at taruti.net
Thu Dec 11 16:04:24 EST 2008


What is the correct way to transform code that uses record selection
with TypeEq (like HList) to associated types? I keep running into
problems with overlapping type families which is not allowed unless
they match.

The fundep code:

class Select rec label val | rec label -> val
instance TypeEq label label True => Select (Label label val :+: rest) label val
instance (Select tail field val) => Select (any :+: tail) field val

And a conversion attempt:

class SelectT rec label where
    type S rec label
instance TypeEq label label True => SelectT (Label label val :+: rest) label where
    type S (Label label val :+: rest) label = val
instance (SelectT tail field) => SelectT (any :+: tail) field where
    type S (any :+: tail) field = S tail field

which fails with:

    Conflicting family instance declarations:
      type instance S (Label label val :+: rest) label
        -- Defined at t.hs:19:9
      type instance S (any :+: tail) field -- Defined at t.hs:23:9

How is it possible to get the TypeEq constraint into the type family?

Attached is a complete example that illustrates the problem.

- Taru Karttunen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.hs
Type: text/x-haskell
Size: 1623 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20081211/b7a932d2/t.bin

More information about the Haskell-Cafe mailing list