Hi Meurig,

| I have a function caculate, that includes a local function alterVal. There
| are a fair number of other local definitions as well.
|
| calculate e =
|  let ...
|      alterVal :: ((Int -> Int) -> Int) -> Bool -> Int
|      alterVal alter True = alter (+1)
|      alterVal alter False = alter (-1)

The fact is that you've really been caught by an irregularity in Haskell,
having temporarily forgotten about the special case in the notation for
sections, and about the "subtract" function that was introduced specifically
to deal with examples like this.  See Section 3.5 of the Haskell report for
more details.

General advice: use sections of the form (e op) whenever possible instead
of (op e) (e.g., if the operator is commutative).  The reason that matters
is that (1+) is less likely to be confused with a positive literal 1, but
another payback is that it's also slightly more efficient (by one
reduction!).

The error message that you got from Hugs could be improved by tagging
predicates with line number information.  In fact it would have been
improved
simply by deleting your explicit type signature, which mislead Hugs into
thinking that the error was somewhere other than the alterVal function.

All the best,
Mark

Reply via email to