diff options
author | Mart Lubbers | 2015-04-23 15:10:52 +0200 |
---|---|---|
committer | Mart Lubbers | 2015-04-23 15:10:52 +0200 |
commit | caf697acd1ee77877b7cbe1c3895c47cd6c2df4c (patch) | |
tree | e7dc5d36cbe7bb6def2758d93ab3d8d39fdb405f /fp2/week2/mart/StdIOMonad.icl | |
parent | Merge branch 'master' of github.com:dopefishh/fp1415 (diff) |
started with week2
Diffstat (limited to 'fp2/week2/mart/StdIOMonad.icl')
-rw-r--r-- | fp2/week2/mart/StdIOMonad.icl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fp2/week2/mart/StdIOMonad.icl b/fp2/week2/mart/StdIOMonad.icl new file mode 100644 index 0000000..7f112a7 --- /dev/null +++ b/fp2/week2/mart/StdIOMonad.icl @@ -0,0 +1,22 @@ +module StdIOMonad + +import StdEnv, StdMaybe, StdMonad, StdFile + +:: IO a = IO (*World -> *(a, *World)) + +read :: *World -> (IO String, *World) +read world +# (io, world) = stdio world +# (line, io) = freadline io +# (ok, world) = fclose io +| not ok = abort "Couldn't close console" +| otherwise = line + +instance return IO where + return x = IO (\w = (x, w)) + +instance >>= IO where + >>= (IO f) g = (IO f) + +Start :: *World -> (IO String, *World) +Start world = read |