What are the alternative of monads to use IO in pure functional programming?

前端 未结 7 1040
小蘑菇
小蘑菇 2021-01-31 03:24

monads are described as the haskell solution to deal with IO. I was wondering if there were other ways to deal with IO in pure functional language.

7条回答
  •  深忆病人
    2021-01-31 03:41

    Imperative Functional Programming by Peyton Jones and Wadler is a must read if you are interested in functional IO. The other approaches that they discuss are:

    • Dialogues which are lazy streams of responses and requests

    type Dialogue = [Response] -> [Request]

    main :: Dialogue

    • Continuations - each IO operation takes a continuation as argument

    • Linear types - the type system restricts you in a way that you cannot copy or destroy the outside state, which means that you can't call a function twice with the same state.

提交回复
热议问题