-- the main was a function in the last example, but here -- are other more normal functions (very very simple ones) -- first something that is not really a function, -- this takes nothing as a parameter, and returns an Int function1 :: Int -- defintion function1 = 5 -- code -- functions always have types, so an implicit defintion. Haskell is quite clever and can often -- figure out what is going on without you, however it is better practice to define ever function - clearly. -- now a function that takes one parameter and returns another function2 :: Int->Int function2 x = x+4 -- Ok, really dull -- more complex function3 :: Int->Int function3 x = x*x+5 -- functions with more than 1 parameter function4 :: Float->Float->Float function4 x y = x*y+(y*5) -- functions calling other functions function5 :: Float->Float->Float->Float function5 x y z = (function4 x y) + z -- the where statement, it is often useful for readability -- to write your functions like this function6 :: Int->Int->Int function6 x y = z+m+p where z = x+y m = x*y p = x*x*x -- entry point for the compiler (required to compile) main :: IO() main = do putStrLn (show function1) putStrLn (show (function2 2)) putStrLn (show (function3 2)) putStrLn (show (function4 2 2)) putStrLn (show (function5 2 2 2)) putStrLn (show (function6 2 2))