两者之间的映射

时间:2016-06-16 16:51:03

标签: haskell

为什么(-1)的情况不适用于此:

λ> (+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 个答案:

答案 0 :(得分:3)

它将(-1)解释为-1而不是((-) 1)

尝试((-) 1) <$> Right 10