4
我對以下程序感到困惑。在RankNTypes中使用函數組合時出現類型錯誤
{-# LANGUAGE RankNTypes #-}
newtype A a = A (forall f. Applicative f => f a)
good :: a -> A a
good x = A $ pure $ x
bad :: a -> A a
bad x = A . pure $ x
當嘗試編譯,我得到這個錯誤訊息,抱怨bad
:
Couldn't match type `f0 a'
with `forall (f :: * -> *). Applicative f => f a'
Expected type: f0 a -> A a
Actual type: (forall (f :: * -> *). Applicative f => f a) -> A a
Relevant bindings include
x :: a (bound at huh.hs:8:6)
bad :: a -> A a (bound at huh.hs:8:1)
In the first argument of `(.)', namely `A'
In the expression: A . pure
爲什麼功能good
類型檢測,而GHC不服功能bad
?我能做些什麼來使後一版本工作?據我所知,這兩個例子應該是等價的。
爲什麼downvote? – Hjulle
[相關](http://stackoverflow.com/questions/9468963/runst-and-function-composition)。 – user3237465
以及這一個:http://stackoverflow.com/questions/8343239/type-error-with-rank-2-types-and-function-composition。 – Hjulle