[Haskell-cafe] mapTuple

minh thu noteed at gmail.com
Thu Jan 11 10:51:21 EST 2007


2007/1/11, Marco Túlio Gontijo e Silva <malebria at riseup.net>:
> Em Qui, 2007-01-11 às 16:14 +0100, minh thu escreveu:
> > you might want invistigate "heterogeneous lists" : in your case, it's
> > "heterogeneous typle".
>
> But aren't tuples always heterogeneous?
>
You're right but the fact you apply a function on both element of the
tuple constrains them to have the same type. Thus the problem is
reminiscent of heterogeneous lists:
how can you make (i.e. wrap) two values of different type so they have
(after being wrapped) the same type ?

I couldnt find the page I was refering but found this one:
http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types
Look at the part on heterogeneous list, the examples are the thing you
want (but for a list, not for a tuple).

Oh two things: 1/ I'm a bad haskell programmers since I have not
enough experience (so maybe I'm throwing you in the bad direction but
I prefer to answer so you not have to wait to long...); 2/ It's a bit
of a habit here to answer with quite involved material even when a
noob asks something (which I don't know if you are or not). Thus maybe
the real answer to your question is wether what you ask for is really
the root of the problem (I can't answer for you).

Another way to do what you want if you just want to use the 'show'
function above on some types (and not every instance of Show) is to
wrap each type individually in a variant type something like this:
data MyShowable = S String | B Bool
myShow :: MyShowable -> String

Optionnaly you can then make MyShowable an instance of Show.
This way is much more 'basic level' haskell than the wiki page above.

Cheers,
mt


More information about the Haskell-Cafe mailing list