[Haskell-cafe] Most Important GHC extensions to learn/use?

James Cook mokus at deepbondi.net
Fri Jun 1 16:37:38 CEST 2012

On Jun 1, 2012, at 6:11 AM, Gábor Lehel wrote:

> On Fri, Jun 1, 2012 at 6:29 AM, wren ng thornton <wren at freegeek.org> wrote:
>>    TypeFamilies (aka TFs)
>>        These are really nifty and they're all the rage these days. In
>>        a formal sense they're equivalent to fundeps, but in practice
>>        they're weaker than fundeps.
> Is that still true? The reason used to be that we didn't have
> superclass equalities, but we do have them now since 7.2. The only
> drawbacks I know of relative to FDs are that it's sometimes more
> typing, not supported by GeneralizedNewtypeDeriving, and doesn't allow
> OverlappingInstances (ick).

In addition to other things mentioned today in the "Fundeps and overlapping instances" thread, type families have no way of defining injective type functions where the range includes already-existing types.

For example, if you define:

> type family Succ a

there is no way (that I've found) to define it in such a way that the compiler can "see" that Succ a ~ Succ b => a ~ b.

The equivalent in MPTCs+FDs would be:

> class Succ a b | a -> b, b -> a

There is more discussion of this particular weakness at http://hackage.haskell.org/trac/ghc/ticket/6018 .

Also, there are less-common usages of fundeps that may be translatable to type families but not easily, when there are complex interrelationships between type variables.  For example, type-level binary operations will sometimes have fundeps such as "a b -> c, a c -> b, b c -> a" - that is to say, any two determines the third.

-- James

More information about the Haskell-Cafe mailing list