io actions Flashcards
what are io functions
non pure functions that depends on the state of the world
why can io functions return no value
they simply achieve the side effect of the functions e.g. changing the state if the world
which type class is io part of
monads
in which two ways can we run io functions
do keyword
(»=)
what is the do keyword
an indented block
which three things can a line in a do block be
an io action
a generator that runs an action and return binds the value to an identifier
a let clause calling pure functions
what must the last line of the do block do
return an io type
how do we turn an any type into an io value
calling return or pure on them
what is the main functions
a non pure function that takes no arguments, returns no value
what does .system.Environment do
accesses command line arguments
what does System.Exit do
sets program return values
what does the main function do
joins together the functionality in pure functions
in which ways can we print to the terminal
putChar
putStr
putStrLn (/n at the end)
in which ways can we read from the terminal
getChar
getLine
what is the difference between print and putStr
print prints anything part of the show class while putStr only accepts strings
how can we use putStr on a v,aye that isn’t a string
converting it to show
putStr(show. )
what does the filePath type indicate
they the function deals with file names and paths
IOMode
access types for the files e.g. read
openFile :: FilePath -> IOMode -> IOHandle
opens the file and returns the handle
what is the point of the handle in file io
allows you to access the same file later
withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
opens the file passes a function to process it then closes once the function has exited
readFile :: FilePath -> IO (String)
reads the file
writeFile :: FilePath -> IO ()
writes to the file