
Marco Túlio Gontijo e Silva wrote:
is there a way to defined something as a map to use in tuples? I tried this:
mapTuple f (a, b) = (f a, f b)
But the type inferred to it is not as generic as I wanted:
mapTuple :: (t -> t1) -> (t, t) -> (t1, t1)
What you seem to want to do is impossible. Just want type would you want to assign to mapTuple? I bet you can't even express that in natural language, no wonder it's impossible in Haskell. Types that are possible, not completely useless, but still impossible to infer, could be: mapTuple :: (forall a . a -> a) -> (a,a) -> (a,a) mapTuple :: (forall a . a -> f a) -> (a,a) -> (f a, f a) (for suitable f or f in a suitable class) Most generalizations turn out to be useless, because there aren't any functions of the needed type that could be passed to mapTuple.
mapTuple show ("string", True)
So you want mapTuple :: forall c . (c a, c b) => (forall a . c a => a -> r) -> (a,b) -> (r,r) which infortunately is only pseudo-Haskell, since c would be a variable that ranges over type classes, and that doesn't exist. I guess you might be able to fake sauch a variable by explicitly passing a dictionary, but that's more complicated than passing the show function twice. So I'd recommend to just forget about it and live with mapTuple taking two functions. In that case you don't even need mapTuple, since it already exists under the name of (***) in Control.Arrow, along with other goodies. You could readily restrict mapTuple to the Show class, giving showTupleWith :: (Show a, Show b) => (forall a . Show a => a -> r) -> (a,b) -> (r,r) but there aren't that many functions it would accept as argument, mostly just show composed with something that operates on strings. -Udo -- If your life was a horse, you'd have to shoot it.