on master help sign in
Merge pull request #1774 from raichoo/master
2e645e2raichoo
libs/effects/Effect/File.idr+14
@@ -87,6 +87,20 @@ instance Handler FileIO IO where
87 handle (FH h) EOF k = do e <- feof h
87 handle (FH h) EOF k = do e <- feof h
88 k e (FH h)
88 k e (FH h)
89
89
90+instance Handler FileIO (IOExcept a) where
91+ handle () (Open fname m) k = do h <- ioe_lift $ openFile fname m
92+ valid <- ioe_lift $ validFile h
93+ if valid then k True (FH h)
94+ else k False ()
95+ handle (FH h) Close k = do ioe_lift $ closeFile h
96+ k () ()
97+ handle (FH h) ReadLine k = do str <- ioe_lift $ fread h
98+ k str (FH h)
99+ handle (FH h) (WriteString str) k = do ioe_lift $ fwrite h str
100+ k () (FH h)
101+ handle (FH h) EOF k = do e <- ioe_lift $ feof h
102+ k e (FH h)
103+
90-- -------------------------------------------------------------- [ The Effect ]
104-- -------------------------------------------------------------- [ The Effect ]
91FILE_IO : Type -> EFFECT
105FILE_IO : Type -> EFFECT
92FILE_IO t = MkEff t FileIO
106FILE_IO t = MkEff t FileIO