2012-02-26 27 views
20

我得到一個錯誤,Constraint不在範圍內,當我嘗試寫一個簡單的例子,什麼是對GHC 7.4.1約束各種語法?

{-# LANGUAGE UndecidableInstances, 
      MultiParamTypeClasses, 
      KindSignatures, 
      Rank2Types, 
      ConstraintKinds, 
      FlexibleInstances, 
      OverlappingInstances, 
      TypeFamilies #-} 

type family A a :: Constraint 

的錯誤是,

> ghci test.hs 
[1 of 1] Compiling Main    (test.hs, interpreted) 

test.hs:10:20: Not in scope: type constructor or class `Constraint' 
Failed, modules loaded: none. 

約束同義詞似乎按預期方式工作,

type ShowOrd a = (Ord a, Show a) 

在此先感謝。出現

回答

26

你的錯誤由Constraint存在造成的,勿庸置疑,不在範圍內。你會想從GHC.Primfrom GHC.Exts導入。

似乎有點奇怪,啓用ConstraintKinds不會自動將其帶入作用域,就像它在我躺在的7.3.2快照構建中所做的那樣,但是在那裏。

+0

真棒,謝謝! – gatoatigrado 2012-02-26 06:10:27

+0

是否有從,而不是GHC.Prim導入一個正式的地方。一個可能允許它在支持這些擴展的其他編譯器上工作。 – semicolon 2016-04-30 19:23:32