


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Class: FUNCTIONAL LANGUAGES; Subject: Computer Science; University: Portland State University; Term: Unknown 1989;
Typology: Study notes
1 / 42
This page cannot be seen from the preview
Don't miss anything!
I/O Actions in Haskell Mark P Jones Portland State University
An IO action is a value of type IO T T is the type of values that it produces
action
(>>) :: IO a -> IO b -> IO b p >> q is an I/O action in which the output of p is ignored by q p >> q == p >>= \x -> q (where x does not appear in q)
inIO :: (a -> b) -> a -> IO b An action inIO f applies the function f to each input of type a and produces outputs of type b as its results
mapM :: (a -> IO b) -> [a] -> IO [b] An action mapM f takes a list of inputs of type [a] as its input, runs the action f on each element in turn, and produces a list of outputs of type [b]
putStr :: String -> IO () putStrLn :: String -> IO () An action putStr s takes a String input and outputs it on the terminal producing a result of type () putStrLn s does the same thing but adds a trailing new line
print :: Show a => a -> IO () A print action takes a value whose type is in Show and outputs a corresponding String on the terminal
The WebActions module provides the following I/O actions: getText :: URL -> IO String getByteString :: URL -> IO ByteString writeByteString :: String -> ByteString -> IO () downloadTo :: FilePath -> URL -> IO () getTags :: URL -> IO [Tag] getHrefs :: URL -> IO [URL] getHTML :: URL -> IO [TagTree] getXML :: URL -> IO [Content]
return url
= getText = putStr
return url
= getText = inIO (length. lines) = print
return url
= getTags = inIO (unlines. map show) = putStr