[Haskell-cafe] tuple and HList

David Menendez zednenem at psualum.com
Sun Mar 20 12:02:26 EST 2005

John Meacham writes:

> This was brought up in passing in a recent conversation on
> haskell-cafe
> http://www.haskell.org//pipermail/haskell-cafe/2005-March/009321.html
> It certainly seems like an interesting idea, Would type inference
> still work okay? 
> The other problem mentioned is that they are not quite isomorphic,
> since HLists are equivalant to (a,(b,c)) rather than (a,b,c), but
> changing HCons so that it is strict in its second argument makes them
> behave the same I think..

Since most of the HList functionality is defined using type classes, we
could probably declare a new type, TCons, make it strict in the second
argument, and use it alongside HCons.

    data TCons a b = TCons a !b

One way t make tuples into sugar for HLists would be to effectively have
a series of declarations like these:

    type (a,b)   = TCons a (TCons b HNil)
    type (a,b,c) = TCons a (TCons b (TCons c HNil))

But then we can't use tuples in instance declarations. That is, there
isn't any way to desugar 'instance Functor ((,) a)' without using a type

On the other hand, using HLists for tuples means we can have projection
functions that work on any tuple arity, which would be nice.
David Menendez <zednenem at psualum.com> <http://www.eyrie.org/~zednenem/>

More information about the Haskell-Cafe mailing list