urgent..haskell mini interpreter

Posted by mohamed elshikh on Stack Overflow See other posts from Stack Overflow or by mohamed elshikh
Published on 2010-05-15T16:52:57Z Indexed on 2010/05/15 17:04 UTC
Read the original article Hit count: 220

Filed under:
|

i'm asked to implement this project and i have problems in part b which is the eval function this is the full describtion of the project

You are required to implement an interpreter for mini-Haskell language. An interpreter is dened in Wikipedia as a computer program that executes, i.e. performs, instructions written in a programming language. The interpreter should be able to evaluate functions written in a special notation, which you will dene. A function is dened by: Function name Input Parameters : dened as a list of variables. The body of the function. The body of the function can be any of the following statements: a) Variable: The function may return any of the input variables. b) Arithmetic Expressions: The arithmetic expressions include input variables and addition, sub- traction, multiplication, division and modulus operations on arithmetic expressions. c) Boolean Expressions: The Boolean expressions include the ordering of arithmetic expressions (applying the relationships: <, =<, >, >= or =) and the anding, oring and negation of Boolean expressions. d) If-then-else statements: where the if keyword is followed by a Boolean expression. The then and else parts may be followed by any of the statements described here. e) Guarded expressions: where each case consists of a boolean expression and any of the statements described here. The expression consists of any number of cases. The rst case whose condition is true, its body should be evaluated. The guarded expression has to terminate with an otherwise case. f) Function calls: the body of the function may have a call to another function. Note that all inputs passed to the function will be of type Int. The output of the function can be of type Int or Bool. To implement the interpreter, you are required to implement the following: a) Dene a datatype for the following expressions: Variables Arithmetic expressions Boolean expressions If-then-else statements Guarded expressions Functions b) Implement the function eval which evaluates a function. It takes 3 inputs: The name of a function to be evaluated represented as a string. A list of inputs to that function. The arguments will always be of datatype Int. A list of functions. Each function is represented as instance of the datatype that you have created for functions. c) Implement the function get_type that returns the type of the function (as a string). The input to this function is the same as in part b.

here is what i've done data Variable = v(char)

data Arth= va Variable | Add Arth Arth | Sub Arth Arth | Times Arth Arth | Divide Arth Arth

data Bol= Great Arth Arth | Small Arth Arth | Geq Arth Arth | Seq Arth Arth | And Bol Bol | Or Bol Bol | Neg Bol

data Cond =

data Guard =

data Fun =cons String [Variable] Body data Body= bodycons(String) |Bol |Cond |Guard |Arth

© Stack Overflow or respective owner

Related posts about haskell

Related posts about homework