這個代碼是從https://wiki.haskell.org/Partial_application初學者Haskell - 如何實現這個功能?
採取我試圖實現這個功能:
comp2 :: (a -> b) -> (b -> b -> c) -> (a -> a -> c)
comp2 f g = (\x y -> g (f x) (f y))
使用
*Main> comp2 3 4
但收到異常:
<interactive>:19:1:
Non type-variable argument in the constraint: Num (a -> b)
(Use FlexibleContexts to permit this)
When checking that `it' has the inferred type
it :: forall a b c.
(Num (a -> b), Num (b -> b -> c)) =>
a -> a -> c
*Main>
如何實現comp2
功能?
請注意'comp2 == flip on',其中'on'在'Data.Function'中定義。 – chepner