everyday programs and exceptions Flashcards

1
Q

base library

A

provides the core runtime

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

hackage

A

third party libraries

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

what are some of the top level module hierarchies

A

control
data
foreign
ghc
system
text

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

control module

A

control-flow and functions
e.g.exceptions, concurrency

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

data module

A

representation
e.g. graphs and trees

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

foreign module

A

interactivity with other languages via the ffi (foreign function interface)

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

which language do we usually use to call haskell functins

A

c

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

ghc module

A

compiler specific

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

system module

A

interactivity with the os, command line, variables, processes etc
e.g. io functions

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

text module

A

representing texts without using strings

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

what is a benefit of the text module

A

enables language conversion

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

when should we use exceptions

A

for things that go wrong rarely not as regular error reporting
e.g. cant write as the disk is too full

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

what is the module for exceptions

A

control.exceptions

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

what are the three main types of exceptions and what are they used for

A

IO exception: for io actions
ErrorCall: generated by calling the error function
SomeException: represents every type of error

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

how is control.exceptions represented

A

via data

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

how can we make our own error handling without using exceptions

A

have a run function that calls the function doing the data
that function returns 2 values in a tuple with one of them being a number indicating whether there was an error
the run function takes this and calls the appropriate exception handling function if required

17
Q

why do we make our own error handling without using exceptions

A

haskell doesnt have a control flow in the same way that java does

18
Q

what does the chaining function look like and what does it do

A

> > =
used for multiple io functions and updates the state of the world as it goes

19
Q

data.char

A

for individual characters
e.g. upper to lower case and back
unicode and back

20
Q

data.list

A

more complex that the list functions in the prelude
can also be used on strings as theyre a list of characters

21
Q

lines (data.list)

A

creates an array from a given string with \n being the separator

22
Q

unlines (data.list)

A

creates a string from an array with \n between

23
Q

words (data.list)

A

creates an array from a given string with white space as separators

24
Q

unwords (data.list)

A

creates a string from an array with white spaces between

25
concat (data.list)
combines lists
26
concatMap (data.list)
combines lists then maps them into one list
27
which 3 functions can we use to split lists
span break splitAt
28
fromMaybe
just = returns the value nothing = returns the default
29
mapMabye
maps only the just values
30
what does the catch function definition look like
catch :: Exception e => IO a -> (e -> IO a) -> IO a
31
how does the catch function work
it has a constraint so e has to be an exception it takes in an io and an exception handler if no error then just returns the io if error then runs the handler and returns the value from that
32
how do we pass in a list of handlers into the catch functin
must create a handler type and make the exceptions equal to it as the catch function requires all the exceptions to be the same type