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
below:
square x = x*x
'.' is not always a namespace-separator like '::','.','-' in c++ or '.' in
java.
it is used as an operator, too.
(.) :: (b-c) - (a-b) - (a-c)
(f . g) x = f (g x)
remember the types of fst and snd:
fst :: (a,b)-a
snd :: (a,b)-b
so the function (.) combines
square :: Int - Int
with fst to
Marc A. Ziegert wrote:
'.' is not always a namespace-separator like '::','.','-' in c++ or '.' in
java.
it is used as an operator, too.
(.) :: (b-c) - (a-b) - (a-c)
(f . g) x = f (g x)
remember the types of fst and snd:
fst :: (a,b)-a
snd :: (a,b)-b
so the function (.) combines
square :: Int
you are correct,but as in the following,
(square . fst) :: (Int,b) - Int
(Char.toUpper . snd) :: (a,Char) - Char
you get a Int and Char out of the two composed functions, namely square.fst,
Char.toUpper.snd.But in the type declaration of
pair, which appeared to me,it meant its
Wenduan,
you get a Int and Char out of the two composed functions, namely
square.fst, Char.toUpper.snd.But in the type declaration of
pair, which appeared to me,it meant its arguments must be two
functions which are of the same type namely a,whereas Int and
Char passed to as arguments are of