[Haskell-cafe] Announcing OneTuple-0.1.0

Lennart Augustsson lennart at augustsson.net
Fri Oct 3 07:10:14 EDT 2008

Let me pick one example.  Let's make a class that can convert between
tuples and lists.
Of course there are restriction when this works, but it can still be useful.

class TupleList t l | t -> l where
    tupleToList :: t -> l
    listToTuple :: l -> t

instance TupleList () [a] where
    tupleToList () = []
    listToTuple [] = ()

-- XXX This doesn't work, and is just wrong.
--instance TupleList (a) [a] where
--    tupleToList (a) = [a]
--    listToTuple [a] = (a)

instance TupleList (a,a) [a] where
    tupleToList (a1,a2) = [a1, a2]
    listToTuple [a1,a2] = (a1, a2)

instance TupleList (a,a,a) [a] where
    tupleToList (a1,a2,a3) = [a1, a2, a3]
    listToTuple [a1,a2,a3] = (a1, a2, a3)

On Fri, Oct 3, 2008 at 8:17 AM, Jason Dusek <jason.dusek at gmail.com> wrote:
> Jason Dagit <dagit at codersbase.com> wrote:
>  Perhaps I am lacking in imagination, but I still can't see the
>  value of one tuples.
> --
> _jsn

More information about the Haskell-Cafe mailing list