I’m reading the guide in learnyouahaskell.com . One sentence mentioned “where” can be shared globally, but no example was given, so where can I find some details, please?
“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.”
From Chapter 4: Syntax in Functions:
Here is an illustration:
The function
fhas a body for each of the patterns(Left x)and(Right x). The binding ofdoubleisn’t shared across the function bodies, and therefore this code isn’t valid Haskell.If we want to access
doublefrom both of the function bodies, we have to move it out of thewhereclause:That’s all that the quoted paragraph means.