on master help sign in
Merge pull request #1977 from jfdm/stdio-effect-print

Added 'Print' functions to STDIO effect.

commit32171edd725805433e87039280df75aa03dae873 authorDavid Christiansen <david@davidchristiansen.dk> dateThu 5 Mar 2015, 12:39 (12 years ago) parent97bc9df49b2d30
1 file changed+11−4
libs/effects/Effect/StdIO.idr+11−4
libs/effects/Effect/StdIO.idr+11−4
@@ -9,8 +9,8 @@ import Control.IOExcept
99
1010||| The internal representation of StdIO effects
1111data StdIO : Effect where
12− PutStr : String -> { () } StdIO ()
13− GetStr : { () } StdIO String
12+ PutStr : String -> { () } StdIO ()
13+ GetStr : { () } StdIO String
1414 PutCh : Char -> { () } StdIO ()
1515 GetCh : { () } StdIO Char
1616
@@ -22,13 +22,13 @@ data StdIO : Effect where
2222instance Handler StdIO IO where
2323 handle () (PutStr s) k = do putStr s; k () ()
2424 handle () GetStr k = do x <- getLine; k x ()
25− handle () (PutCh c) k = do putChar c; k () ()
25+ handle () (PutCh c) k = do putChar c; k () ()
2626 handle () GetCh k = do x <- getChar; k x ()
2727
2828instance Handler StdIO (IOExcept a) where
2929 handle () (PutStr s) k = do ioe_lift $ putStr s; k () ()
3030 handle () GetStr k = do x <- ioe_lift $ getLine; k x ()
31− handle () (PutCh c) k = do ioe_lift $ putChar c; k () ()
31+ handle () (PutCh c) k = do ioe_lift $ putChar c; k () ()
3232 handle () GetCh k = do x <- ioe_lift $ getChar; k x ()
3333
3434-------------------------------------------------------------
@@ -58,3 +58,10 @@ getStr = call $ GetStr
5858getChar : { [STDIO] } Eff Char
5959getChar = call $ GetCh
6060
61+||| Given a parameter `a` 'show' `a` to standard output.
62+print : Show a => a -> { [STDIO] } Eff ()
63+print a = putStr (show a)
64+
65+||| Given a parameter `a` 'show' `a` to a standard output, terminating with a newline
66+printLn : Show a => a -> { [STDIO] } Eff ()
67+printLn a = putStrLn (show a)