PLT11 course -- assignment 9

(C) Ralf Lämmel, Andrei Varanovich, University of Koblenz Landau

Logistics

Assignment

Resources

Check out the directory.

See the main module for running the semantics.

You are well advised not to try understanding other modules. (They are complicated.)

To run the main module, be in the right directory:

$ pwd
/Users/laemmel/projects/slps/topics/NielsonN07/Haskell/src
$ ghci While/DenotationalSemantics/SimpleMain0.hs 
GHCi, version 42: http://www.haskell.org/ghc/  :? for help
[1 of 3] Compiling While.SimpleAbstractSyntax
[2 of 3] Compiling While.DenotationalSemantics.SimpleDirectStyle
[3 of 3] Compiling While.DenotationalSemantics.SimpleMain0
> main
120

1st option

Starting from SimpleDirectStyle.hs, which implements direct style of denotational semantics for the language While, create a module SimpleContinuationStyle.hs to implement the semantics for continuation style, as discussed in the lecture. The types of the semantic functions for expressions are not affected, but the type of the semantic function for statement changes as follows:

type Cont = State -> State
execute :: Stm -> Cont -> Cont

Once you have converted the style, please also add support for raise and handlers, which was the main application of continuation style in the lecture.


2nd option

Starting from SimpleDirectStyle.hs, which implements direct style of denotational semantics for the While language, create a module SimpleMaybeStyle.hs to make good use of Maybe, while preserving direct style and all other details as much as possible. In particular, Nothing should be returned by lookup of a variable from a state, if no value is available for the variable. The use of Maybe also must propagate through the interpreter definition. In particular, the revised types of the semantic functions are these:

evala :: Aexp -> State -> Maybe Z
evalb :: Bexp -> State -> Maybe Bool
execute :: Stm -> State -> Maybe State

You need to find appropriate implementations for the auxiliary operators to lookup from and to modify a state. You can model the state as a list of variable-value pairs. (Optionally, you can use a corresponding Haskell module Data.Map, which helps here.)