patternMinor
Why is the second operation of a Monad called bind?
Viewed 0 times
whythecalledoperationsecondbindmonad
Problem
I understand how monadic computation works, I am just wondering where does the name come from. I cannot relate the thing that the
I understand why we have the name
bind operator actually does (i.e. unbox the monadic value, and then apply a function to produce another monadic value) and the name bind (which, to me, means associate two things together).I understand why we have the name
return (I suspect it has to do with the Haskell do-notation), although IMHO it isn't a good name either. Return indicates a change in control flow but it really isn't, all it does is produce a monadic value.Solution
In Haskell the syntactic sugar for
That is, the result of the computation
In ML-like languages the same thing is written as
which again is a form of binding a variable to a value.
As for
bind e₁ (λ x . e₂) isdo x ← e₁
e₂That is, the result of the computation
e₁ is bound to x, after which e₂ is computed.In ML-like languages the same thing is written as
let x = e₁ in e₂which again is a form of binding a variable to a value.
As for
return being a control-flow mechanism – that's precisely what it is. You are probably thinking of control mechanisms for branching, looping, raising exceptions etc. Well, return is the one that ends a computation and yields a result.Code Snippets
do x ← e₁
e₂let x = e₁ in e₂Context
StackExchange Computer Science Q#124291, answer score: 5
Revisions (0)
No revisions yet.