Category
suspicious
Shape
A recursive String stepper puts the unread suffix into a returned constructor field and also passes that same suffix as the walk argument (or stores it again in the next state). Every step then keeps an extra copy of the rest of the input.
Prefer returning a mode that means "resume on the suffix already in hand" without embedding that suffix a second time.
Bad
type Mode is Data:
MDone{saved: String}
def step(rest: String) -> Mode:
match rest:
case SNil{}:
MDone{rest}
case SCon{_', t}:
step(t)
Good
type Mode is Data:
MRest{}
def step(rest: String) -> (Mode & String):
match rest:
case SNil{}:
(MRest{}, rest)
case SCon{_', t}:
step(t)
(or thread rest only as the walk argument and leave it out of Mode)
Category
suspiciousShape
A recursive String stepper puts the unread suffix into a returned constructor field and also passes that same suffix as the walk argument (or stores it again in the next state). Every step then keeps an extra copy of the rest of the input.
Prefer returning a mode that means "resume on the suffix already in hand" without embedding that suffix a second time.
Bad
Good
(or thread
restonly as the walk argument and leave it out ofMode)