[Haskell-beginners] Function Type Confusion ..

Tom Poliquin poliquin at softcomp.com
Tue Jan 27 12:42:54 EST 2009


I was reading "Arrows and Computation" 

http://www.soi.city.ac.uk/~ross/papers/fop.ps.gz

(trying to lose my 'beginner' status) when I saw (on page
one) 

add :: (b -> Int) -> (b -> Int) -> (b -> Int)
add f g b = f b + g b

It seemed like the type definition was wrong (short at least).

I tried it anyway ..

module Main where
add :: (b -> Int) -> (b -> Int) -> (b -> Int)
add f g b = f b + g b
main = do
   x <- return $ add (+2) (+3) 7
   print x

The program compiles and  runs and produces '19' !

For fun I loaded into ghci and got what I believe is the proper
type ..

   *Main> :t add
   add :: (b -> Int) -> (b -> Int) -> b -> Int


When I try the same thing with something simpler
(leaving a bit off the type definition)
I get the expected error (by me) ..

module Main where
dog :: Int -> Int
dog a b = a + b

main = do
   x <- return $ dog 2 3
   print x

Main.hs:5:0:
    The equation(s) for `dog' have two arguments,
    but its type `Int -> Int' has only one

What am I missing? .. Apparently something fundamental
about type definitions ..

Any help appreciated.

Tom



More information about the Beginners mailing list