Often I have a function of such pattern:
f :: a -> b
f x = case x of
... -> g ...
... -> g ...
...
... -> g ...
where g = ...
There is an syntactic sugar for almost this case:
f :: a -> b
f ... = g ...
f ... = g ...
...
f ... = g ...
Unfortunately I can’t attach my where to it: I’ll obviously get bunch of not in scopes.
I can make g a separate function, but it’s not nice: my module’s namespace will be polluted with utility functions.
Is there any workaround?
I think that your first example isn’t bad at all. The only syntactic weight is
case x of, plus->instead of=; the latter is offset by the fact that you can omit the function name for each clause. Indeed, even dflemstr’s proposedgohelper function is syntactically heavier.Admittedly, it’s slightly inconsistent compared to the normal function clause syntax, but this is probably a good thing: it more precisely visually delimits the scope in which
xis available.