0

Why doesn't the case with (-1) work here:

λ> (+1) <$> Right 10
Right 11
Prelude
λ> (-1) <$> Right 10

<interactive>:22:1: error:
    • Non type-variable argument in the constraint: Num (a -> b)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        it :: forall a b a1. (Num (a -> b), Num a) => Either a1 b
Prelude
λ> (*1) <$> Right 10
Right 10
Prelude
λ> (/1) <$> Right 10
Right 10.0
Prelude
λ> 

1 Answers1

3

It's interpreting (-1) as -1 rather than ((-) 1)

Try ((-) 1) <$> Right 10

Daenyth
  • 35,856
  • 13
  • 85
  • 124
  • Yep that works. But what if I wanted to do 10 - 1, how do I get that to work? –  Jun 16 '16 at 16:54
  • 1
    You could use `flip` or write the lambda out. There's also `subtract`, as linked in the dup question – Daenyth Jun 16 '16 at 16:56