haskell-course

Haskell Features

Comments

Definitions

theAnswer :: Int
theAnswer = 42
doubleMe :: Int -> Int
doubleMe x = 2 * x

doubleMe = \x -> 2 * x
foo x y = 2 * x + y
xor :: Bool -> Bool -> Bool
xor True False = True
xor False True = True
xor False False = False
xor True True = False
xor :: Bool -> Bool -> Bool
xor True False = True
xor False True = True
xor _ _ = False
and :: Bool -> Bool -> Bool
and True x = x
and False _ = False
fib :: Int -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
  myMax :: Int -> Int -> Int
  myMax m n
    | m > n = m
    | m < n = n
    | otherwise = m
bmiTell :: Float -> Float -> String  
bmiTell weight height  
    | bmi <= 18.5 = "You're underweight, you emo, you!"  
    | bmi <= 25.0 = "You're supposedly normal. Pffft, I bet you're ugly!"  
    | bmi <= 30.0 = "You're fat! Lose some weight, fatty!"  
    | otherwise   = "You're a whale, congratulations!"  
    where bmi = weight / height ^ 2
cylinder r h =
    let sideArea = 2 * pi * r * h  
        topArea = pi * r ^2  
    in  sideArea + 2 * topArea  
and :: Bool -> Bool -> Bool
and y x =
  case y of
    True -> x
    False -> False

Polymorphism