State Monad, why not a tuple?

后端 未结 3 1500
-上瘾入骨i
-上瘾入骨i 2021-01-02 08:11

I\'ve just wrapped my head around monads (at least I\'d like to think I have) and more specifically the state monad, which some people that are way smarter then me figured o

3条回答
  •  既然无缘
    2021-01-02 08:48

    Ah, yes, if the question is: should I use a single-tag Discriminated Union that carries a data value of type T, or should I just use T, then you can use either.

    In Haskell, you need to use a data tag with monads, since the Haskell do syntax infers the monad type based on value types (a tuple representation could be an instance of at most a single Monad). Whereas in F#, computation expressions are explicit about the monad type (e.g. state { ... } or async { ... } or whatever) so this restriction is not necessary, the same representation type could be used for multiple monads.

提交回复
热议问题