io actions Flashcards

1
Q

what are io functions

A

non pure functions that depends on the state of the world

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

why can io functions return no value

A

they simply achieve the side effect of the functions e.g. changing the state if the world

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

which type class is io part of

A

monads

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

in which two ways can we run io functions

A

do keyword
(»=)

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

what is the do keyword

A

an indented block

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

which three things can a line in a do block be

A

an io action
a generator that runs an action and return binds the value to an identifier
a let clause calling pure functions

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

what must the last line of the do block do

A

return an io type

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

how do we turn an any type into an io value

A

calling return or pure on them

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

what is the main functions

A

a non pure function that takes no arguments, returns no value

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

what does .system.Environment do

A

accesses command line arguments

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

what does System.Exit do

A

sets program return values

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

what does the main function do

A

joins together the functionality in pure functions

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

in which ways can we print to the terminal

A

putChar
putStr
putStrLn (/n at the end)

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

in which ways can we read from the terminal

A

getChar
getLine

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

what is the difference between print and putStr

A

print prints anything part of the show class while putStr only accepts strings

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

how can we use putStr on a v,aye that isn’t a string

A

converting it to show
putStr(show. )

17
Q

what does the filePath type indicate

A

they the function deals with file names and paths

18
Q

IOMode

A

access types for the files e.g. read

19
Q

openFile :: FilePath -> IOMode -> IOHandle

A

opens the file and returns the handle

21
Q

what is the point of the handle in file io

A

allows you to access the same file later

22
Q

withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r

A

opens the file passes a function to process it then closes once the function has exited

23
Q

readFile :: FilePath -> IO (String)

A

reads the file

24
Q

writeFile :: FilePath -> IO ()

A

writes to the file

25
hClosd e :: Handle -> IO ()
closes an open file handle
26
hGetChar :: Handle -> IO (Char)
read char /string
27
hPutChar :: Handle -> Char -> IO()
write char /string
28
what do we use to check if a file exists and what is its type definition
doesFileExist :: FilePath -> IO (Bool)