Bind sequences a computation that produces a contextual value with a function that consumes that value and produces the next contextual computation. In free-monad code, it turns a sequence of domain actions into nested continuations while preserving one unified recipe type. section 6.3.1 section 6.3.4
Bind improves a sequential recipe in three related ways:
- Replaces do-notation’s left-arrow steps with explicit >>= calls. section 6.3.1
- Passes each intermediate SandwichBody to the continuation for the next action. section 6.3.1
- Keeps arbitrarily long free-monad chains under the common type SandwichRecipe a instead of growing nested action types. section 6.3.4
A sandwich recipe
mySandwich2 = startNewSandwich Toast Tomato >>= (\body1 -> addComponent Cheese body1 >>= (\body2 -> addComponent Salt body2 >>= (\body3 -> finishSandwich (Just Toast) body3))) section 6.3.1
mySandwich3 :: SandwichRecipe Sandwich mySandwich3 = startNewSandwich Toast Tomato >>= addComponent Cheese >>= addComponent Salt >>= finishSandwich (Just Toast)
Compare explicit nested lambdas with partial application: the same bind chain becomes shorter without losing its sequencing behavior. section 6.3.1




