1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are guards?
Guards can be use to constrain when equations can match (aka. When an expression evaluates to a Bool value), as an alternative to conditional statements.
What is Haskell’s chosen version of polymorphism?
Parametric.
What is parametric polymorphism? How does Haskell implement this?
Haskell uses “generic programming” or parametric polymorphism, and implements this through a single definition of a function that applies generically and identically to values of any type using type variables.
What is a type variable?
Variables representing any type.
What other types of polymorphism do OO languages implement?
Ad-hoc - Where we overload functions by writing multiple implementations, one for each type.
Subtype - We relate datatypes by using a supertype instance for all subtypes.
What is overloaded polymorphism?
Sometimes we want to restrict the number of types a polymorphic function can use. We do this by establishing class constraints in the type definition like “(+) :: Num a => args” which ensures that that function can only use instance types of that class.
So, what is a (type) class?
A group of types supporting certain collective methods.
So, what is a (type) instance?
A type within a type class is an instance of that class which can implement those methods.
So, what is a (type) interface?
A method that all instances of that type class should support. Haskell allows us to add interfaces to existing types and vice versa, which is very difficult in other languages.
What are uncurried functions?
Uncurried functions have multiple arguments packaged in tuples/lists. Arguments are taken one at a time.
What are curried functions?
‘Currying’ is the process of breaking down a multi-argument function into a series of single-argument functions. Type annotation associates to the right [Int -> Int -> Int = Int -> (Int -> Int)], and function application associated to the left [mult x y z = ((mult x) y) z.
Can you compare equality of functions?
No. To check if two functions are equal, you’d have to apply them to every possible input and check that their outputs are always equal. For functions with infinite domains (like Int → Int), this is undecidable, so not computable in general.