Skip to content

Commit 821e706

Browse files
committed
docs(tutorials): add fuel consumption rules explanation in generator tutorial
1 parent b35d2af commit 821e706

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

docs/tutorials/06-beyond-fuel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ genSomething Dry = -- Base case: no fuel, choose non-recursive constructors
134134
genSomething (More f) = -- Recursive case: spend fuel or use optimization
135135
```
136136

137+
- When `Fuel` is `Dry`, the generator **must** choose non-recursive constructors (like `PZ`, `Leaf`, `Nil`)
138+
- When `Fuel` is `More f`, the generator **can** choose recursive constructors (like `PS`, `Node`, `Cons`)
139+
- Each recursive call consumes one unit of `Fuel` (calls with `f` instead of `More f`)
140+
- This guarantees termination: eventually `Fuel` reaches `Dry` and recursion stops
141+
142+
This is why higher `Fuel` values produce larger structures — more recursive steps are allowed before hitting the `Dry` base case.
143+
137144
But the key insight is: **deriveGen doesn't always spend fuel on recursion**. It depends on the type of recursion.
138145

139146
### SpendingFuel: Manual Implementation

0 commit comments

Comments
 (0)