#### Function declaration

You might be used to declare functions like this: In `C`: ``` int f(int x, int y) { return x*x + y*y; } ``` In Javascript: ``` function f(x,y) { return x*x + y*y; } ``` in Python: ``` def f(x,y): return x*x + y*y ``` in Ruby: ``` def f(x,y) x*x + y*y end ``` In Scheme: ``` (define (f x y) (+ (* x x) (* y y))) ``` Finally, the Haskell way is: ``` haskell f x y = x*x + y*y ``` Very clean. No parenthesis, no `def`. Don't forget, Haskell uses functions and types a lot. It is thus very easy to define them. The syntax was particularly well thought for these objects. #### Exercise Declare correctly the function g(x,y)=x2-y2+x -y ``` active haskell -- show Replace undefined by your definition g = undefined -- show Should display 6 and -8 main = do print \$ g 3 2 print \$ g 3 4 ``` @@@ Solution ``` active haskell -- show g x y = x*x - y*y + x - y -- /show main = do print \$ g 3 2 print \$ g 3 4 ``` @@@

#### A Type Example

`Int` the type `Int`
`Int -> Int` the type function from `Int` to `Int`
`Float -> Int` the type function from `Float` to `Int`
`a -> Int` the type function from any type to `Int`
`a -> a` the type function from any type `a` to the same type `a`
`a -> a -> a` the type function of two arguments of any type `a` to the same type `a`