[Haskell-cafe] Re: Type Families: deleting from HList

oleg at okmij.org oleg at okmij.org
Wed Aug 4 02:30:35 EDT 2010

Serguey Zefirov wrote:
> Is it possible to delete an element from heterogenous list using type
> families alone?
> I can do it using multiparameter type classes:
> class Del a list result
> instance Del a (a,list) list
> instance Del a list list' => Del a (a',list) list'
> instance Del a () ()

I'm afraid you'll find that class quite difficult to use: lots of type
annotations will be required. For example, if we define

	del :: Del a li lo => a -> li -> lo
	del = undefined

and write
	test1 = del True ('a',(True,()))
the compiler will complain because it doesn't know which instance to

BTW, since GHC checks for overlapping lazily, the fact that GHC
accepts a set of instance declarations does not tell that the
instances `work'. The problems may lurk, becoming apparent when we
define values that attempt to use the instances.

In order for something like Del to be useful, functional dependencies
are needed. It is easy to see that Del uses overlapping
instances. That answers the question: since type families do not
support overlapping instances, one cannot re-write Del using type
families alone.

One may ask is it possible to define some sort of type inequality
using type families. And the answer is yes, recently discussed at

More information about the Haskell-Cafe mailing list