import Prelude hiding (lookup) data Exp = Num

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

import Prelude hiding (lookup) data Exp = Num Int | Add Exp Exp | Sub Exp Exp | Mul Exp Exp | Div Exp Exp | Var String | Let String Exp Exp | App Exp Exp | Fnc String Exp deriving (Show) type Env = [(String, Val)] data Val = CVal Int | FnVal String Exp Env | Error String deriving (Show) {-Implement a function lookup:: Env -> String -> Val that looks up the value of a variable within a context. This function returns the value of the variable if found and returns an error otherwise. -} lookup :: Env -> String -> Val -- code here-- {- Implement a function eval:: Exp -> Env -> Val to evaluate an expression with an initial context and return a value. Errors occur in the following cases: (a) Left-hand-side of a function application is not a function. (b) Use an undefined variable (c) Arithmetic expression where operand is not a number -} eval :: Env-> Exp -> Val

-- code here -- 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,