Out of scope: `String 'data constructor

I am new to Haskell. I get this "Out of scope:" String "data constructor in almost every line of code that contains" String "

Please take a look at my code and let me know what I am doing wrong. I really appreciate your help, thanks.

import Data.Maybe

data Op = Add | Sub | Mul | Div | And | Or | Not | Eq | Less | Great
    deriving (Eq, Show)

data Exp = Literal Value
     | Primitive Op [Exp]
     | Variable String
     | If Exp Exp Exp
     | Let [(String, Exp)] Exp
    deriving (Show, Eq)

data Value = Number Int
       | Bool Bool
    deriving (Eq, Show)

type Env = [(String, Value)]

eval :: Env -> Exp -> Value
eval e (Literal v) = v
eval e (Variable x) = fromJust (lookup x e)
--22
prim :: op -> [Value] -> Value
prim Add [Number a, Number b] = Number (a+b)
prim And [Bool a, Bool b] = Bool (a && b)
prim Sub [Number a, Number b] = Number (a-b)
prim Mul [Number a, Number b] = Number (a*b)
prim Div [Number a, Number b] = Number (a/b)
prim Or [Bool a, Bool b] = Bool (a || b)
prim Not [Bool a] = Bool (not a)
prim Eq [Number a, Number b] = Bool (a == b)
prim Eq [String a, String b] = Bool (a == b) 
prim Less [Number a, Number b] = Bool (a < b)
prim Less [String a, String b] = Bool (a < b)
prim Great [Number a, Number b] = Bool (a > b)
prim Great [String a, String b] = Bool (a > b) 

      

+3


source to share


1 answer


Looks like you forgot to add String

to the datatype Value

?



data Value = Number Int
       | Bool Bool
       | String String
    deriving (Eq, Show)

      

+8


source







All Articles