Why does Haskell not have an I Monad (for input only, unlike the IO monad)?

后端 未结 5 1209
攒了一身酷
攒了一身酷 2021-02-18 15:29

Conceptually, it seems that a computation that performs output is very different from one that performs input only. The latter is, in one sense, much purer.

I, for one,

5条回答
  •  太阳男子
    2021-02-18 15:40

    When you obtain input, you cause side-effects that changes both the state of the outside world (the input is consumed) and your program (the input is used). When you output, you cause side-effects that only change the state of the outside world (output is produced); the act of outputting itself does not change the state of your program. So you might actually say that O is more "pure" than I.

    Except that output does actually change the execution state of your program (It won't repeat the same output operation over and over; it has to have some sort of state change in order to move on). It all depends on how you look at it. But it's so much easier to lump the dirtiness of input and output into the same monad. Any useful program will both input and output. You can categorize the operations you use into one or the other, but I'm not seeing a convincing reason to employ the type system for the task.

    Either you're messing with the outside world or you're not.

提交回复
热议问题