[英]Data Constructor promotion in GHC-7.6
我有這個代碼:
class SymbolSet tpe where
data Symbol tpe :: *
data SSet tpe where
Identity :: tpe -> SSet tpe
And :: SSet tpe -> Symbol tpe -> SSet tpe
class HasElem a b where
instance (SymbolSet tpe) => HasElem (And (Identity tpe) s) s
instance (HasElem sset s) => HasElem (And sset s) s
這是在GHC-7.4中編譯的。 但是,在轉向GHC-7.6時,它開始出現編譯錯誤:
'And' of tpe `forall tpe. tpe -> Symbol * tpe -> SSet tpe' is not promotable
在挖掘文檔時,我發現在GHC-7.6與GHC-7.4的 “數據類型升級”頁面中添加了一個新的條款
我們不會提升其構造函數是多態的,涉及約束或使用存在量化的數據類型。
我的問題是:
你沒有說你正在使用哪個版本的GHC 7.6或包含你所使用的擴展,所以我猜測了一下。
這張票似乎回答了你的問題1,雖然我自己並不完全理解這個問題。 在您的特定示例中,我認為SSet
不可升級,因為它的一個參數( Symbol tpe
)是一個關聯類型,它帶來了SymbolSet
約束。
如果我將Symbol
移出類,我們會得到提升類型,但是現在我們得到了類似的不匹配錯誤:
{-# LANGUAGE DataKinds , TypeFamilies , GADTs , MultiParamTypeClasses #-}
class SymbolSet tpe where
-- data Symbol tpe :: *
data Symbol tpe :: *
-- ...
我可以通過向HasElem
添加類型簽名來編譯整個shebang:
{-# LANGUAGE DataKinds , TypeFamilies , GADTs , MultiParamTypeClasses, FlexibleInstances #-}
class SymbolSet tpe where
-- MOVED OUT OF CLASS:
data Symbol tpe :: *
data SSet tpe where
Identity :: tpe -> SSet tpe
And :: SSet tpe -> Symbol tpe -> SSet tpe
-- ADDED KIND SIGNATURES:
class HasElem (a :: SSet *) (b :: Symbol *) where
instance (SymbolSet tpe) => HasElem (And (Identity tpe) s) s
instance (HasElem sset s) => HasElem (And sset s) s
我真的不了解您的代碼,因此可能對您不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.