具有通用数据类型的简单 haskell 程序出错

Error in simple haskell program with generic data type

我正在 Haskell 中编写一个通用解释器,但我对环境的定义有疑问。

data Variable a = Variable {
     name :: String,
     vtype :: String,
     value :: a -- Rather than value :: Int
}

Variable结构体定义完成后,我需要定义程序(环境)的状态,简单来说就是一个List of Variable。如果我写

type Env = [Variable]

我遇到了以下问题:

generic_interpreter.hs:11:13: error: * Expecting one more argument to Variable' Expected a type, but Variable' has kind * -> *' * In the type [Variable]' In the type declaration for `Env' 11 | type Env = [Variable]

你能帮帮我吗?提前致谢。

您的 Variable 类型有一个类型参数 a,因此您不能使用 [Variable],因为列表需要具体类型。

因此,您可以定义一个类型 Env a,它是 Variable 类型 a:

的列表
type Env <b>a</b> = [Variable <b>a</b>]