Tutorial by Examples

A function can be defined using guards, which can be thought of classifying behaviour according to input. Take the following function definition: absolute :: Int -> Int -- definition restricted to Ints for simplicity absolute n = if (n < 0) then (-n) else n We can rearrange it using gua...
Haskell supports pattern matching expressions in both function definition and through case statements. A case statement is much like a switch in other languages, except it supports all of Haskell's types. Let's start simple: longName :: String -> String longName name = case name of ...
Given this function: annualSalaryCalc :: (RealFloat a) => a -> a -> String annualSalaryCalc hourlyRate weekHoursOfWork | hourlyRate * (weekHoursOfWork * 52) <= 40000 = "Poor child, try to get another job" | hourlyRate * (weekHoursOfWork * 52) <= 120000 = "Money...

Page 1 of 1