单形库包含以下片段(希望在7.8中编译):
{-# LANGUAGE DataKinds, ExistentialQuantification, FlexibleContexts, GADTs #-}
{-# LANGUAGE ImpredicativeTypes, PolyKinds, RankNTypes, TypeFamilies #-}
{-# LANGUAGE TypeOperators, UndecidableInstances #-}
class Monomorphicable k where
type MonomorphicRep k :: *
withPolymorphic :: Monomorphicable k
=> MonomorphicRep k -> (forall a. k a -> b) -> b
withPolymorphic k trans = undefined
-- | Flipped version of 'withPolymorphic'.
liftPoly :: Monomorphicable k
=> (forall a. k a -> b) -> MonomorphicRep k -> b
liftPoly = flip withPolymorphic然而,在7.10中,GHC投诉:
Couldn't match type ‘k2 a0 -> b’ with ‘forall (a :: k0). k1 a -> b’
Expected type: MonomorphicRep k2 -> (k2 a0 -> b) -> b
Actual type: MonomorphicRep k1
-> (forall (a :: k0). k1 a -> b) -> b
Relevant bindings include
liftPoly :: (forall (a :: k). k2 a -> b) -> MonomorphicRep k2 -> b
(bound at Data/Type/Monomorphic.hs:45:1)
In the first argument of ‘flip’, namely ‘withPolymorphic’
In the expression: flip withPolymorphic当然,如果我将liftPoly的定义更改为
liftPoly a b = withPolymorphic b a然后7.10是快乐的。这里发生了什么事?在处理多态函数时,7.10应该更严格吗?因为所有的东西都有签名,所以它似乎并不是单形限制。
发布于 2015-04-18 04:23:52
flip的类型是
flip :: (x -> y -> z) -> (y -> x -> z)要键入check liftPoly,我们必须以多态类型forall a. k a -> b实例化变量y。这是非谓词多态的一个实例。
正如https://ghc.haskell.org/trac/ghc/wiki/ImpredicativePolymorphism的页面所说,
我们做了各种尝试来支持非预测性,所以有一个标志
-XImpredicativeTypes。但它不起作用,而且绝对不受支持。如果你使用它,你就只能靠你自己了;我对将要发生的事情不作任何承诺。
因此,当ImpredicativeTypes的行为在不同版本的GHC之间发生变化时,不要太惊讶。
https://stackoverflow.com/questions/29712710
复制相似问题