2016-06-16 7 views
0

なぜここ(-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 
λ> 

答えて

3

それは-1としてではなく、((-) 1)

(-1)の解釈の作品((-) 1) <$> Right 10

+0

うんを試してみてください。しかし、もし私が10 - 1をやりたければどうすればそれを働かせることができますか? –

+1

'flip'を使うか、ラムダを書くことができます。 dupの質問にリンクされているように 'subtract'もあります – Daenyth

関連する問題