UNSW   Faculty of Engineering myCSEPRINT VERSIONSITE MAP  
cse | School of Computer Science and Engineering (CRICOS Provider No. 00098G)
    #About CSE     #Undergraduate Study     #Postgraduate Study     #Timetables & Courses     #Research & Publications     #People & Work Units     #Help & Resources     #News & Events     #High School Portal

Last updated 16.03.04

Advanced Functional Programming [COMP4132]

Session 1, 2004

Exercises: Semantics of IO, Part I

The following exercises are based on the operational semantics for IO operations defined in Simon Peyton Jones' Tackling the Awkward Squad.

Using the Operational Semantics

Assume the following program in do notation:

main =
  do
    c1 <- getChar
    c2 <- getChar
    putChar (Char.chr (Char.ord c1 + Char.ord c2))

It can be rewritten to use the monad primitives instead of the do notation as follows:

main = getChar >>= \c1 ->
       getChar >>= \c2 ->
       putChar (Char.chr (Char.ord c1 + Char.ord c2))

Use the transition semantics in the same way as it is done on Page 27 of Peyton Jones' paper to execute this program (ignore the use of IORefs in that example for the moment). Note the interaction between the evaluation function and the transition rules.

NB: Assume that the addition of two numbers "x" and "y" gives a result of "x + y", where the "+" here is not the addition in the object language (ie, Haskell), but in the mathematical meta language in which we reason about object language programs.

Top Of Page

 ###
Site maintained by webmistress@cse.unsw.edu.au
Please read the UNSW Copyright & Disclaimer Statement