Typing and Programming with Functions Flashcards
what is a type?
a collection of related values
what is ⊥?
“bottom” - non-terminating stuff
how is type defined in Haskell?
e :: t means e has type t
what is a tuple?
a sequence of values of different types, surrounded by brackets ().
what does an apostrophe mean in Haskell?
it signifies a curried function
what is a curried function? (give an example)
a function that takes arguments one at a time
add’ :: Int -> (Int -> Int)
add’ x y = x + y
what are polymorphic functions?
functions that’s types contain multiple variable types, e.g. length :: [a] -> Int
What does it mean for a function to be overloaded?
a polymorphic funtion is overloaded if its type contains at least 1 class constraint, e.g. sum :: Num a => [a] -> a
give an example of a conditional expression in Haskell
signum :: Int -> Int
signum n = if n < 0 then -1 else
if n==0 then 0 else 1
give an example of a guarded equation on Haskell
signum n | n < 0 = -1
| n == 0 = 0
| otherwise = 1
what does _ signify?
a wildcard pattern that matches any argument value
use _ to define True or False with ands
True && b = b
False && _ = False
how are patterns matched?
in order
how is disjunction symbolised in Haskell?
||
use || to define True or False
False || b = b
True || _ = True