Hacker News new | past | comments | ask | show | jobs | submit login

What about the Identity monad? Does that "force sequencing"? What "sequencing relationship" does it create?

If you are convinced that the Identity monad does "force sequencing" then you are also convinced that lazy evaluation "forces sequencing" (because the Identity monad is just lazy evaluation). That would be a fairly controversion conviction. If you are not convinced that the Identity monad "forces sequencing" then can you explain in more detail the meaning of your claim "What a Monad does is to force sequencing by creating a data dependency.".




The identity monad's sequencing is just basic cause and effect: you need to have produced an `a` in order to get a `b`.

The sequencing is very obvious from the signature of `>>=`. You don't need to know anything about any instances to see that it's there.


> The identity monad's sequencing is just basic cause and effect: you need to have produced an `a` in order to get a `b`.

You most certainly do not! See https://news.ycombinator.com/item?id=16420742


It's in the signature. `b` has a causal dependency on `a` because `a` is on the left hand side of the arrow and `b` is on the right hand side of the arrow. That's it. Functional programming 101. There's no way around this.

The operational semantics and details of thunks are not relevant here. Tricks with `undefined` are not relevant here. This is just the meaning of the arrow type.


If that were true, why do you need a monad for sequencing? Why doesn’t function composition suffice, or something of the form a -> (a -> b) -> b?


Because the values have extra "stuff" surrounding them. That's why it's `m a` and not just `a`: the `m` holds the invisible context that enriches the `a`.

Although your example is exactly what's happening in the identity monad, because there is no extra stuff.


Monads have been called "executable semicolons", because you can define a function to be executed each time the program passes from one statement to the next.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: