3. Types and classes Flashcards
How are chars and string stored?
char: ‘a’
string: “ask”
What is a curried function and give an example of one.
A function that uses the fact that we can return functions.
mult :: Int -> (Int -> (Int -> Int))
mult x y z = x * y * z
What are polymorphic types?
A type that can be many types.
i.e. [a] or b
What are class constraints and what is the syntax?
specifies the type.
C a where C is the name of the constraint and a is a type of variable.
i.e. (+) :: Num a => a -> a -> a
How to check inequality?
(/=) :: a -> a -> Bool
How to get the negative of a number?
negate :: a -> a
How do we get the sign of a number?
signum :: a -> a
How to divide two numbers?
> 7 div
2
3
How to get the modulo of a fraction?
> 7 mod
2
1