4 * 5
.
3 `elem` [3,4,5]
to use a binary function as an infix operatorf x
theAnswer :: Int
theAnswer = 42
doubleMe :: Int -> Int
doubleMe x = 2 * x
doubleMe = \x -> 2 * x
:t
:t
on foo
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
Integer
is unboundedfib :: 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
where
clauses
String
is a list of Char
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
let
clausescylinder r h =
let sideArea = 2 * pi * r * h
topArea = pi * r ^2
in sideArea + 2 * topArea
case
expressionsand :: Bool -> Bool -> Bool
and y x =
case y of
True -> x
False -> False
id x = x
. What type should we assign to id
? id :: Int -> Int
or Bool -> Bool
is not general enough
id :: a -> a
($) :: (a -> b) -> a -> b
(.) :: (b -> c) -> (a -> b) -> a -> c