我使用GHCI 7.0.3與以下程序實現的類型級列表:XTypeOperators擴展不起作用的編譯
{-# LANGUAGE TypeOperators #-}
data True
data False
-- List
data Nil
data Cons x xs
-- Type-level infix operator must begin with ':'
data x ::: xs
infixr 5 ::: -- set precedence level to 5 (tight)
它編譯,但是當我測試它:
:t (undefined :: True:::Nil)
(轉換爲類型True:::Nil
當什麼的undefined
類型?)我得到這個錯誤:
Illegal operator `:::' in type `True ::: Nil'
Use -XTypeOperators to allow operators in types
事實上,當我開始GHCI旗
-XTypeOperators
我得到預期的結果:
(undefined :: True ::: Nil) :: True ::: Nil
我的問題是:爲什麼不等效的編譯工作:
{-# LANGUAGE TypeOperators #-}
編輯:如果編譯指示不延伸到GHCi環境比我有另一個難題。我想這個方案:
class And b1 b2 b | b1 b2 -> b where
andf :: b1 -> b2 -> b
-- truth table
instance And True True True where andf = undefined
instance And True False False where andf = undefined
instance And False True False where andf = undefined
instance And False False False where andf = undefined
它需要以下編譯:
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
但是一旦編譯,我可以在ghci中使用它:
*Main> :t andf (undefined::True) (undefined::False)
andf (undefined::True) (undefined::False) :: False
我想在列表中的情況下解釋程序甚至無法用類型級別的運算符:::
解析表達式,而在多參數類的情況下,命令行是可解析的。但是,想一想,GHCi使用多參數類和函數依賴來執行類型推斷,不是嗎?這種類型推斷是在GHCi中完成的,而不是通過調用編譯代碼中的某個函數,對吧?
+1 .ghci文件 – 2011-12-26 20:37:54