Homework #3

Due: Mon, Jul 24, 23:59

How to Submit

  • Submit one solution per team (each team can have 1–3 members), through TEACH. Put the names and ONID IDs of all team members as a comment at the top of the file.

  • Your submission should consist of two files named MiniMiniLogoSem.<your-username>.hs, where is the ONID ID of the team member who submitted the file.

  • These files must compile without errors in GHCi. Put all non-working parts of your solution in comments! If your file does not compile, the TA will not evaluate it.

  • If you can’t solve a problem, you can get partial credit by describing in comments what you tried and where you got stuck.

  • Late submissions will not be accepted. Do not send solutions by email.


MiniMiniLogo is a simplified version of the MiniLogo language you worked with in Homework #2, which was itself a simplified version of the Logo Language for programming simple 2D graphics.

MiniMiniLogo is like MiniLogo, except it doesn’t have macros, variables, or addition. This leaves only a very simple syntax.

int ::= (any integer number)
prog ::= ε | cmd; prog sequence of commands
mode ::= down   |   up pen status
cmd ::= pen mode change pen mode
| move ( int , int ) move pen to a new position

The following MiniLogo program (that draws a 2x2 square with its bottom-left corner at the origin) is also a valid MiniMiniLogo program.

pen up; move (0,0);
pen down; move (2,0); move (2,2);
          move (0,2); move (0,0);

A Haskell implementation of the abstract syntax of MiniMiniLogo is already provided for you in the file MiniMiniLogo.hs. It also provides some functions to generate programs that draw simple shapes.

In this assignment, you will be implementing the semantics of MiniMiniLogo. The meaning of a MiniMiniLogo program is (1) the change in the state of the pen and (2) a list of the lines to draw.

Conceptually, the MiniMiniLogo execution environment consists of two parts:

  • a canvas rooted at position (0,0) and extending infinitely upward and to the left
  • a pen which is always located at a certain position on the canvas, and which can be in one of two states, either up or down

The move command moves changes the location of the pen from one absolute point to another. If the pen is down when it begins its move, it draws a straight line connection the starting point to the ending point. If the pen is up when it begins its move, it just moves to the new point without drawing a line. The state of the pen can be changed using the pen command as illustrated in the example program above.

The support file Render.hs defines types for representing the state of the pen, and provides a library for rendering the output of a MiniMiniLogo program as an SVG image in an HTML5 file.


Template: MiniMiniLogoSem.template.hs

Support Files (don’t edit or submit these):

  1. Implement cmd, the semantic function for MiniMiniLogo commands (Cmd). Note that a command updates the state of the pen and possibly draws a line. Therefore, the semantic domain is State -> (State, Maybe Line).

  2. Implement prog, the semantic function for MiniMiniLogo programs (Prog). A program changes the state of the pen, and may draw several lines. Therefore, the semantic domain is State -> (State, [Line]).

After you have implemented prog, you can use the draw function in the template to run a MiniMiniLogo program and render its output to HTML, which you can then load into your browser. To see if your semantic functions are working correctly, you can compare the results of running draw demo with this image: MiniMiniLogo-Demo.png.

Bonus Problems

Use your creativity to produce a MiniMiniLogo program that draws an amazing picture! I will show off the most amazing pictures (anonymously) in class.

To get extra credit, you must do two things:

  1. Define the amazing variable in the template file. This should be the MiniMiniLogo program that generates the amazing picture.

  2. Submit the .html file produced by running draw amazing. To make things easier for me (or the TA), first rename this file to reflect your amazing picture. For example, if your amazing picture is the Mona Lisa, name the file MonaLisa.html.

The amount of extra credit will be proportional to the technical impressiveness and/or artistry of the amazing picture.

To make a truly amazing picture, you will probably need to define some helper functions that generate parts of your MiniMiniLogo program, similar to box, nix, and steps in MiniMiniLogo.hs.

Back to course home page