http://learnyouahaskell.com/syntax-in-Functions”rel=“nofollow” 第4章:职能中的协同效应:
where
bindings aren t shared across function bodies of different patterns. If you want several patterns of one function to access some shared name, you have to define it globally.
Here is an illustration:
f (Left x) = double x
f (Right x) = double x
where
double x = 2 * x
The function f
has a body for each of the patterns (Left x)
and (Right x)
. The binding of double
isn t shared across the function bodies, and therefore this code isn t valid Haskell.
If we want to access double
from both of the function bodies, we have to move it out of the where
clause:
double x = 2 * x
f (Left x) = double x
f (Right x) = double x
该款所引述的意思就是这样。