From Simple IO to Monad Transformers by J Adrian Zimmer

From Simple IO to Monad Transformers by J Adrian Zimmer

Author:J Adrian Zimmer
Language: eng
Format: epub
Publisher: J Adrian Zimmer


Here is a program you can compile and execute to test this. In it I have extracted the interior object from pairs getLine getLine, converted it to a string and printed it.

pairs :: Monad m => m t -> m u -> m (t,u)

pairs lst1 lst2 = do

x <- lst1

y <- lst2

return (x,y)

main = pairs getLine getLine >>= (\z -> putStrLn (show z))

This program, of course, silently asks for two lines of input. As a further exercise, you might want to change it so that it requests input with a "Input? " prefix. Then execution would look like

Input? line 1

Input? line 2

("line 1","line 2")



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.