module HW4 where {- 11/4/09: Due to my mis-definition of tweekList on slide 6 of Environments.pdf, I am rescinding my no extension policy. Homework is now due Monday, November 10th, by 3pm. -} {- For each of the following questions, put your answer directly below the question. Email your code directly to Adam Procter: amp269@mizzou.edu. (1) You must use a text editor (e.g., vi, textpad, emacs, etc.) to prepare your solution. (2) You must write type declarations for each and every one of your Haskell definitions. (3) The program you turn in must be the product of your effort alone. This problem set is the most involved so far. You must not wait until the last minute to start it. There will be absolutely *no* extensions for this assignment. IMPORTANT: Furthermore, do *not* drop by EBN17 without an appointment. EBN 17 is a working laboratory and I will not tolerate the arbitrary interruption of my graduate students. This occurred a number of times before the last assignment's due date. You have been warned. -} {- Question 1. Recall the data declarations for TopLevel and Exp on slide 7 of ImpCoreSemantics.pdf. Define instances of the Show class for TopLevel and Exp. To receive credit, you *must* produce strings that look like the concrete syntax for ImpCore shown in chapter 2 of Ramsey/Kamin. -} {- Question 2. Using the Environments.pdf slides, give definitions for the global, function definition, and function argument environments. Each will consist of a data declaration and an instance of the environment "interface" functions from slide 6 of Environments.pdf. To receive credit, you *must* use the function implementation of environments (i.e., the one using tweek). -} {- Question 3. Using your answers to 2., give a data declaration for the ImpCore expression state and ImpCore top-level state. See slide 11 of ImpCoreSemantics.pdf. Call these data declarations ExpStore and TopStore. -} {- Question 4. Recall slide 19 of ImpCoreSemantics.pdf. A pseudo-Haskell translation of the FormalAssign rule is given there and this same approach can be used to implement all the rules for ImpCore. Write a function, eval :: ExpStore -> ExpStore, that implements the operational semantics rules: Literal, FormalVar, GlobalVar, FormalAssign, GlobalAssign, IfTrue, IfFalse, WhileIterate, WhileEnd, EmptyBegin, Begin, ApplyUser, ApplyAdd, ApplyEqTrue, and ApplyEqFalse. -} {- Question 5. Continuing 4., write a Haskell function, top :: TopStore -> TopStore, that implements the following evaluation rules for top-level items: EvalExp, DefineGlobal, and DefineFunction. -}