-- -- -- IO -- -- -- -- IO -- def print {a} (x: a) : IO () := do write x write "\n" flush () def printToPort {a, b} (port: a) (x: b) : IO () := do writeToPort port x writeToPort port "\n" def display {a} (x: a) : IO () := do write x flush () def displayToPort {a, b} (port: a) (x: b) : IO () := do writeToPort port x def eachLine (proc: String -> IO ()) : IO () := do let eof := isEof () if eof then return () else do let line := readLine () proc line eachLine proc def eachLineFromPort {a} (port: a) (proc: String -> IO ()) : IO () := do let eof := isEofPort port if eof then return () else do let line := readLineFromPort port proc line eachLineFromPort port proc def eachFile (files: [String]) (proc: String -> IO ()) : IO () := match files as list string with | [] -> return () | $file :: $rest -> do let port := openInputFile file () <- eachLineFromPort port proc () <- closeInputPort port eachFile rest proc -- -- Collection -- def each {a} (proc: a -> IO ()) (xs: [a]) : IO () := match xs as list something with | [] -> do return () | $x :: $rs -> do proc x each proc rs -- -- Debug -- def debug expr := io $ do print (show expr) return expr def debug2 msg expr := io $ do display msg print (show expr) return expr