A value constructor creates a value of an algebraic data type. Its visibility determines how much of the representation client code can depend on: public constructors permit pattern matching over internal structure, while opaque modules hide that structure. section 6.3.2 section 3.2.4
Value constructors play distinct roles in the examples:
- Free stores an action and its continuation; Pure terminates the chain while holding the resulting value. section 6.3.2
- BoolValue, IntValue, FloatValue, and StringValue construct the alternatives of Value. section 3.2.4
- Smart constructors wrap construction behind functions, allowing the type and its representation to remain opaque. section 3.2.4
Wrapping an operation in Free
A manually constructed recipe uses Free with a Pure placeholder: `Free (StartNewSandwich Toast Tomato Pure)`. Monadic binding later replaces that placeholder with the continuation, producing one nested computation chain. section 6.3.2
data Free t a
= Pure a #1
| Free #2
(t #3
(Free t a) #4
)
Inspect the recursive definition showing Pure as the value-holding terminator and Free as the constructor carrying an action and continuation. section 6.3.2
