From : KENNA M.W. Sent : 29 November 2005 12:43:32 To : HANDLEY S.L. Subject : FW: Functional Programming CW3 Here is the response I had from Dr. Berger. Its goooooooood news! -----Original Message----- From: Ulrich Berger [mailto:U.Berger@swansea.ac.uk] Sent: Tue 29/11/2005 11:22 To: KENNA M.W. Subject: Re: Functional Programming CW3 KENNA M.W. wrote: > Dr. Berger > I am having some trouble understanding exactly what coursework 3 is > asking us to do.. im not sure exactly what the environment is? > > type Env = [(String, Expr)] > > Would it be that String is the name of the variable and Expr is the > arithmetic expressions? > For example: [(threePlusFile, Add(3)(5))] Exactly. The content of a file you are loading would typically be something like x = 3 + y * z y = 5*z z = 8+1 more precisely "x = 3 + y * z\ny = 5*z\nz = 8+1\n" The corresponding environnment (which is computed by createEnv) is [("x", Add 3 (Mul "y" "z")),("y",Mul 5 "z"),("z",Add 8 1)] > If you could just clarify exactly what we need the user to input that > would also be very helpfull. You compile Expr.hs and run main. Then you work in a similar way as you do in Hugs. Here is a sample session: ----------------------------------------------------------------------- Prelude> :l Expr.hs Reading file "Expr.hs": Reading file "Parse.hs": Reading file "ShowTree.hs": Reading file "Expr.hs": Hugs session for: /usr/share/hugs/lib/Prelude.hs Parse.hs ShowTree.hs Expr.hs Main> main Welcome to Expr ... Type :? for help Expr>> :? :s show content of specified file evaluate expression (needs to be improved) :t sorry, not available yet :? display this list of commands :q exit Expr interpreter Expr>> 5 5 Expr>> :s Expr.hs import Parse import ShowTree -- Template for an interpreter for mini programming language Expr. -- Features to be added: -- load file containing definitions of the form x = expr -- evaluate arithmetic expressions built from numbers, variables, + and * -- show syntax tree of expression main :: IO () main = do putStrLn hello reploop emptyEnv -- read-eval-print-loop putStrLn goodbye ... (whole content of file Expr.hs) -- Needs to be improved! -- see the implementation of exprInt in Parse.hs for a hint of how to do it. Expr>> :q [Leaving Expr] Main> ---------------------------------------------------------------------------- It is your task to improve this interpreter as specified on the coursework sheet. For example, evaluating expressions presently works for numbers only: Expr>> 3 3 Expr>> 3+5 incorrect expression: 3+5 Expr>> The reason is that the parser is inadequate. You need to improve it. Hope that helps. UB > Thanks, Mark Kenna -----Original Message----- From: Ulrich Berger [mailto:U.Berger@swansea.ac.uk] Sent: Tue 29/11/2005 13:18 To: KENNA M.W. (342067) Subject: Re: Functional Programming CW3 KENNA M.W. (342067) wrote: > I forgot to ask one question, are we supposed to read the input from the > command line or is it all from a file? Both: on the command line you can (can = should be able to) type Expr>> 3+4 7 but you can also write in some file, say, test.expr, lines like x = 3+4 then load the file Expr>> :l test.expr and evaluate expressions containing x, for example Expr>> x*x 49 UB > Thanks, Mark. >