[Haskell-cafe] Re: Functional dependencies and Peano numbers
byorgey at seas.upenn.edu
Tue Jul 13 06:31:13 EDT 2010
On Sun, Jul 11, 2010 at 12:43:47AM +0200, Jose A. Ortega Ruiz wrote:
> On Sat, Jul 10 2010, wren ng thornton wrote:
> > Yes, you can add multiple dependencies. The syntax is to use , after
> > the first |.
> > While having eight parameters is surely a desperate need for
> > refactoring, there are times when you'd want multiple dependencies.
> > For example, you can say
> > class F a b | a -> b, b -> a where...
> > to express a bijective function on types (that is, for every pair of A
> > and B, if you know one of them then you know what the other must be
> > uniquely).
> I know i should read the relevant articles, but how would one express
> such a bijection using type families?
You would just create two type families, one for each direction of the
type family F1 a :: *
type instance F1 Int = Bool
type instance F1 ...
type family F2 a :: *
type instance F2 Bool = Int
type instance F2 ...
Of course, this is not quite the same thing, since with the MPTC
version we are guaranteed to get a bijection, but there is nothing
forcing F1 and F2 to have anything to do with one another (for example
I could have written type instance F2 Char = Int). But I don't know
whether this would make a difference in practice.
More information about the Haskell-Cafe