Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

IO monads aren't the only way. If all you want is print it's even quite easy.


Please do tell or link to more, if you're willing!


Print alone is easy as you can just have functions output both their normal output and a listing of whatever they printed. These listings then get concatenated together (this is technically "the writer monad", but you don't need to know as much).

IO was originally handled in Haskell as `main :: [String] -> [String]`. More generally, we might think `main :: [Input] -> [Command]`. This is obviously a pure function. If the types Input and Command are a bit like

    Input   = SawChar Char   | Tick UTCTime | FileRecv String
    Command = PrintChar Char | RequestTime  | RequestFile FilePath
you can imagine how a more general effects framework could be done purely.

In practice, monads are a lot simpler than this. In particular, it can be easy to get desynchronized from your Commands and Inputs.

Other language have more explicit effect typing as well. Conor McBride's `Frank` comes to mind, but it's fairly complex.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: