Why are side-effects modeled as monads in Haskell?

前端 未结 8 907
无人共我
无人共我 2020-12-02 03:30

Could anyone give some pointers on why the impure computations in Haskell are modelled as monads?

I mean monad is just an interface with 4 operations, so what was th

8条回答
  •  伪装坚强ぢ
    2020-12-02 04:12

    It's actually quite a clean way to think of I/O in a functional way.

    In most programming languages, you do input/output operations. In Haskell, imagine writing code not to do the operations, but to generate a list of the operations that you would like to do.

    Monads are just pretty syntax for exactly that.

    If you want to know why monads as opposed to something else, I guess the answer is that they're the best functional way to represent I/O that people could think of when they were making Haskell.

提交回复
热议问题