Error in simple haskell program with generic data type

Viewed 64

I'm writing a generic interpreter in Haskell but I have a problem with the definition of the environment.

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

After the definition of the Variable structure, I need to define the status of the program (environment) that is simply a List of Variable. If I write

type Env = [Variable]

I had the following problem:

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]

Can you help me? Thanks in advance.

1 Answers

Your Variable type has a type parameter a, so you can not use [Variable], since the list needs a concrete type.

You thus can define a type Env a that then is a list of Variables of type a:

type Env a = [Variable a]
Related