HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Why is the second operation of a Monad called bind?

Submitted by: @import:stackexchange-cs··
0
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 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 bind e₁ (λ x . e₂) is

do 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.