
Mark and Win-Jan
| I've been trying some examples in functional programming. Most things | work fine, but I have trouble with expressions with 'where' clauses | that define more then one local definition. | ... | For example: | ... | mydiff f = f' | where f' x = ( f (x+h) - f x) / h | h = 0.0001
The second line in the where clause (your attempt to define local variable h) will be treated as if it were part of the first definition (for the variable f'). Why? Because that's what the layout/indentation in your code specifies. In fact, to a Haskell compiler, your input looks a lot like the following, clearly incorrect definition:
mydiff f = f' where f' x = ( f (x+h) - f x) / h h = 0.0001
this explanation is very good but the real confusion comes from the fact that probably there were some TAB characters in the original program. In the text editor used for typing the program the tabs stops were 4 spaces apart as they are usually nowadays because otherwise programs become too wide... But the Haskell report (section B.3) specifies that the TAB characters are 8 characters apart. This is a small point indeed compared to existential polymorphic typing problems, but as author the Haskell Emacs mode, I have been asked quite a few times about the explanation of this kind of behavior. Concrete suggestions about this any one? Guy Lapalme PS: of course, one can specify that tabs insert spaces but then one must be cautious to untabify existing programs.