module IO where import ST type MyState = ((Integer, Integer), String, String) type MyIO a = ST MyState a unitIO :: a -> MyIO a unitIO = unitST bindIO :: MyIO a -> (a -> MyIO b) -> MyIO b bindIO = bindST setIO :: Pos s a -> a -> ST (s, i, o) () setIO p v = \ (s, i, o) -> ((), (snd (p s) v, i, o)) getIO :: Pos s a -> ST (s, i, o) a getIO p = \ (s, i, o) -> (fst (p s), (s, i, o)) readIO :: () -> MyIO Char readIO () = \ (s, c:cs, o) -> (c, (s, cs, o)) eofIO :: () -> MyIO Bool eofIO () = \ (s, i, o) -> (null i, (s, i, o)) writeIO :: Show s => s -> MyIO () writeIO v = \ (s, i, o) -> ((), (s, i, o ++ show v)) fst3 (x, _, _) = x snd3 (_, y, _) = y thd3 (_, _, z) = z atoi :: String -> Integer atoi = read atof :: String -> Double atof = read