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
choose.

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
        http://www.haskell.org/pipermail/haskell-cafe/2010-July/080473.html


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to