Types Flashcards
How to get type of an expression
using :t operator
How to read :: operator
has type of
Evaluate :t “Hello!”
“Hello!” :: [Char]
what is the meaning of -> in type definitions
it is read as ‘maps’ ; so if Int -> Int is seen in the type declaration, it means this function maps Int parameter to Int result
In case of type definition of a function which are parameters and which is for output
Output type is specified as last item in the list separated by ->
Define Int type
Stands for 32 bit integers, both +ve and -ve
Define Integer type
unbounded integer size
Define Float type
Single precision floating point
Define Double type
Double precision floating point
Define Bool type
type boolean; has only two values True and False
Define Char type
used for single characters. string is a list of chars.
What are polymorphic functions
functions having type variables are called polymorphic
Difference between infix and postfix functions; provide examples
Oeprators are infix functionos, where the operator <param2} is the syntax for intfix functions. These are alled as operatrors as well
Describe ‘Eq’ typeclass
used for types that support equality testing, Members of this type class implement == and /==. If there is a Eq in the type description of a function, it uses in its definition somewhere either == or /== operators
What Haskell functions will not implement ‘Eq’ typeclass
IO functions
Describe ‘Ord’ typeclass
used for types that support ordering. For example operators like , =, LT, GT, or EQ
what is the prerequisite of ‘Ord’ typeclass members?
They must be part of ‘Eq’ typeclass as well.
Describe Show typeclass
Members of “Show” typeclass can be presented as strings using the function show. for example show 3 will return “3”
What are not members of ‘Show’ type class?
all functions
Describe Read typeclass
Opposite to Show. Gets a string and returns a type which is a member of “Read”
Evaluate read “5” - 3
2
Evaluate read “[1,2,3,4]” ++ [5]
[1,2,3,4,5]
Evaluate read “True” || False
True
Evaluate read “4”
GHCI will crash, since it does not know what to do with the return value !!!