我想实现具有类型限制的解释大小的简单命题逻辑。但是somhow我无法使用natVal
将类型级别的数字转换为值。示例代码:
import GHC.TypeLits
import Data.Proxy
newtype PropositionalVariable (interpretationSize) = PropositionalVariable {
getVariable :: Int
} deriving (Show, Eq)
instance KnownNat i => Enum (PropositionalVariable i) where
fromEnum = getVariable
toEnum e | e <= 0 = error "Variable must be positive integer"
| (toInteger e) > (natVal (Proxy :: Proxy i)) = error "Variable index overflow"
| otherwise = PropositionalVariable e
给我错误,如:
• Expected a type, but ‘i’ has kind ‘Nat’
• In the first argument of ‘PropositionalVariable’, namely ‘i’
In the first argument of ‘Enum’, namely ‘PropositionalVariable i’
In the instance declaration for ‘Enum (PropositionalVariable i)’
在这种情况下,将类型级别整数转换为值的正确方法是什么?
答案 0 :(得分:0)
您需要打开PolyKindnds
扩展名或给interpretationSize
一种注释。