[Haskell-cafe] Contexts for type family instances

Stephen Tetley stephen.tetley at gmail.com
Sun Dec 12 13:26:48 CET 2010


Hello all

I've a type family DUnit that I use to allow the unit type, usually a
Double, of geometric things (points, vectors...) to be parametric:

> type family DUnit a :: *

E.g for Points

> data Point u = P2 u u

> type instance (Point u) = u

I can make an type instance for Maybe like this, using DUnit on the
right hand side:

> type instance DUnit (Maybe a)       = DUnit a


But pair is a problem. Is there a way to assert both parts of a pair
should have the same DUnit?

The code below won't compile but it should illustrate what I'm trying to do.

> type instance (DUnit a ~ DUnit b) => DUnit (a,b)           = DUnit a

I don't want to pick an arbitrary side, e.g:

> type instance DUnit (a,b)           = DUnit a

or

> type instance DUnit (a,b)           = DUnit b



Thanks

Best wishes

Stephen



More information about the Haskell-Cafe mailing list