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 setXIO :: x -> ST ((x, y), i, o) () setXIO v = \ ((x, y), i, o) -> ((), ((v, y), i, o)) setYIO :: y -> ST ((x, y), i, o) () setYIO v = \ ((x, y), i, o) -> ((), ((x, v), i, o)) getXIO :: () -> ST ((x, y), i, o) x getXIO () = \ ((x, y), i, o) -> (x, ((x, y), i, o)) getYIO :: () -> ST ((x, y), i, o) y getYIO () = \ ((x, y), i, o) -> (y, ((x, y), 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