on master help sign in
Standard IO effect docstrings
commit87418599b50706aada987e26a024728487044c67 authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateWed 16 Apr 2014, 23:12 (13 years ago) parent7d38bcf
1 file changed+17
libs/effects/Effect/StdIO.idr+17
libs/effects/Effect/StdIO.idr+17
@@ -3,12 +3,22 @@ module Effect.StdIO
33import Effects
44import Control.IOExcept
55
6+-------------------------------------------------------------
7+-- IO effects internals
8+-------------------------------------------------------------
9+
10+||| The internal representation of StdIO effects
611data StdIO : Effect where
712 PutStr : String -> { () } StdIO ()
813 GetStr : { () } StdIO String
914 PutCh : Char -> { () } StdIO ()
1015 GetCh : { () } StdIO Char
1116
17+
18+-------------------------------------------------------------
19+-- IO effects handlers
20+-------------------------------------------------------------
21+
1222instance Handler StdIO IO where
1323 handle () (PutStr s) k = do putStr s; k () ()
1424 handle () GetStr k = do x <- getLine; k x ()
@@ -21,23 +31,30 @@ instance Handler StdIO (IOExcept a) where
2131 handle () (PutCh c) k = do ioe_lift $ putChar c; k () ()
2232 handle () GetCh k = do x <- ioe_lift $ getChar; k x ()
2333
34+-------------------------------------------------------------
2435--- The Effect and associated functions
36+-------------------------------------------------------------
2537
2638STDIO : EFFECT
2739STDIO = MkEff () StdIO
2840
41+||| Write a string to standard output.
2942putStr : Handler StdIO e => String -> { [STDIO] } Eff e ()
3043putStr s = PutStr s
3144
45+||| Write a character to standard output.
3246putChar : Handler StdIO e => Char -> { [STDIO] } Eff e ()
3347putChar c = PutCh c
3448
49+||| Write a string to standard output, terminating with a newline.
3550putStrLn : Handler StdIO e => String -> { [STDIO] } Eff e ()
3651putStrLn s = putStr (s ++ "\n")
3752
53+||| Read a string from standard input.
3854getStr : Handler StdIO e => { [STDIO] } Eff e String
3955getStr = GetStr
4056
57+||| Read a character from standard input.
4158getChar : Handler StdIO e => { [STDIO] } Eff e Char
4259getChar = GetCh
4360