[Haskell-cafe] pair (f,g) x = (f x, g x)?

wenduan xuwenduan2010 at gmail.com
Sat Jul 2 02:32:57 EDT 2005

I came across a haskell function on a book defined as following:

pair :: (a -> b,a -> c) -> a -> (b,c)
pair (f,g) x = (f x,g x)

I thought x would only math a single argument like 'a', 1, etc....,but 
it turned out that it would match something else, for example, a pair as 

square x = x*x

pair (square.fst,Char.toUpper.snd) (2,'a')

The type declaration of  pair is what confused me,
pair :: (a -> b,a -> c) -> a -> (b,c),it says this function will take a 
pair of functions which have types of a->b,a->c,which I would take as 
these two functions must have argument of the same type, which is a,and 
I didn't think it would work on pairs as in the above instance,but 
surprisingly it did,can anybody enlighten me?


More information about the Haskell-Cafe mailing list