0

I am trying to figure out how to make haskell happy with the following equation:

f = either id (-1)

it complains:

No instance for (Num (Int -> Int))
  arising from a use of syntactic negation
In the second argument of ‘either’, namely ‘(- 1)’
In the expression: either id (- 1)
In an equation for ‘f’: f = either id (- 1)

Do I have to resort to

f = either id (\x -> x-1)

or maybe there is a a type signature that will make it work?

akonsu
  • 28,824
  • 33
  • 119
  • 194

1 Answers1

4

You can use \x -> x - 1 as you suggest, or subtract 1. Prefix negation is a special case: (-1), unlike (1-), doesn't become a section.

duplode
  • 33,731
  • 7
  • 79
  • 150