In what sense is the IO Monad pure?

后端 未结 9 1705
暗喜
暗喜 2020-12-04 08:41

I\'ve had the IO monad described to me as a State monad where the state is \"the real world\". The proponents of this approach to IO argue that this makes IO operations pure

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 09:07

    Philip Wadler writes:

    In an impure language, an operation like tick would be represented by a function of type
    () -> (). The spurious argument () is required to delay the effect until the function is applied, and since the output type is () one may guess that the function's purpose lies in a side effect. In contrast, here tick has type M (): no spurious argument is needed, and the appearance of M explicitly indicates what sort of effect may occur.

    I fail to understand how M () makes the empty argument list () less spurious but Wadler is pretty clear that monads just indicate a kind of side-effect, they do not eliminate it.

提交回复
热议问题