Types Flashcards

1
Q

How to get type of an expression

A

using :t operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to read :: operator

A

has type of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Evaluate :t “Hello!”

A

“Hello!” :: [Char]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the meaning of -> in type definitions

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In case of type definition of a function which are parameters and which is for output

A

Output type is specified as last item in the list separated by ->

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define Int type

A

Stands for 32 bit integers, both +ve and -ve

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define Integer type

A

unbounded integer size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define Float type

A

Single precision floating point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define Double type

A

Double precision floating point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define Bool type

A

type boolean; has only two values True and False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define Char type

A

used for single characters. string is a list of chars.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are polymorphic functions

A

functions having type variables are called polymorphic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Difference between infix and postfix functions; provide examples

A

Oeprators are infix functionos, where the operator <param2} is the syntax for intfix functions. These are alled as operatrors as well

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe ‘Eq’ typeclass

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What Haskell functions will not implement ‘Eq’ typeclass

A

IO functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe ‘Ord’ typeclass

A

used for types that support ordering. For example operators like , =, LT, GT, or EQ

17
Q

what is the prerequisite of ‘Ord’ typeclass members?

A

They must be part of ‘Eq’ typeclass as well.

18
Q

Describe Show typeclass

A

Members of “Show” typeclass can be presented as strings using the function show. for example show 3 will return “3”

19
Q

What are not members of ‘Show’ type class?

A

all functions

20
Q

Describe Read typeclass

A

Opposite to Show. Gets a string and returns a type which is a member of “Read”

21
Q

Evaluate read “5” - 3

22
Q

Evaluate read “[1,2,3,4]” ++ [5]

A

[1,2,3,4,5]

23
Q

Evaluate read “True” || False

24
Q

Evaluate read “4”

A

GHCI will crash, since it does not know what to do with the return value !!!

25
How to specify 'type annotations' on read?
Use :: operator after the read. for example | read "4" :: Int
26
Show an example of 'type annotator' in an expression
(read "5" :: Float) * 4 which will return 20.0
27
why the expression read "4" crashes?
Since Haskell uses type inference, it has no context to infer the output type from this expression
28
Define 'Enum' typeclass
Its members are types which can be ordered sequentially aka enumerated
29
Describe advantages of Enum class
Its members types can be used in ranges; | They can also be used with succ and pred functions
30
List all types in Enum class
(), Bool, Char, Float, Double, Int, Integer, and Ordering
31
Describe Bounded typeclass
Member types can have an upper and lower limit
32
Evaluate minBound :: Float
Need to check with GHCI and update the answer here
33
Evaluate maxBound :: Float
Need to check with GHCI and update the answer here
34
Evaluate minBound :: Char
What is the value returned by GHCI? Is this ASCII limit or something else..
35
Evaluate miinBound :: (Int,Bool)
(-2147483648, False)
36
Describe Num typeclass
Its members behave as numbers; So Int, Integer, Float, and Double are its members
37
Describe class constraint
In a type description anything before => is known as class constraint. For example :t (==) (==) :: (Eq a) => a -> a -> Bool Here the class constraint is saying the parameter should belong to type class Eq