COMP3161/9164 Concepts of Programming Languages
Term 3, 2025

MinHS Demo

Table of Contents

1. MinHS Demo

This is not actually an assignment, instead, it is a warm-up exercise to demo some of the machinery that will appear in Assignment 1 and Assignment 2.

The MinHS package provided here is a medium-sized Haskell development, defining the syntax of a MinHS language that extends the MinHS language in the lectures with some additional features. The development includes a parser and printer for this language using standard Haskell packages. For this demo we also supply a very simple main program that parses MinHS programs and prints reports of the results of simple queries. We also provide a large collection of example MinHS programs that can be used for testing.

1.1. Haskell sources

You can download the supplied materials as a zip file here. This includes an inner MinHS development and a Cabal/Stack package minhs-0 that includes it.

The supplied Haskell development can be built via either the Cabal build/package system (`cabal build`) or the Stack build/package system (`stack build`). A Makefile is provided that will run either process depending on the configuration in the file 'usestackcabal'. The default is Stack, which is considered slightly more user-friendly. You should be able to find installation instructions for Stack and Cabal by searching for "Haskell stack" or "Haskell cabal".

CSE machines have Cabal installed, and the development has been tested to work using Cabal on CSE machines. However, building all the dependencies takes up a substantial amount of disk space, somewhere between 1 and 2 GB. This may not be possible for all students given disk quota constraints.

We recommend students install on their own hardware if at all possible, and we recommend the use of Haskell Stack.

Let us know (on the forum or class email account) if getting Cabal or Stack set up proves impossible. In particular, if there are difficulties building and running MinHS (as opposed to its dependencies), let us know about issues and workarounds on the forum, as that may be useful to the whole class.

1.2. Differences to the MinHS from Lectures

This version of the MinHS language has two additional types: the Unit type, which just contains the value `()`, and lists as in Haskell.

Instead of just Boolean literals, there is a constructor element `Con` in the abstract syntax, which is used to encode all the supported constructors.

This version of MinHS includes a let-binding construct. More on that below.

Finally, this Haskell package includes a nontrivial module structure and build system. This is a more conventional setup than our experiments in lectures that have mostly used `ghci`. It is still possible to load modules from this development with `ghci` and experiment with them. It is also common to work in an edit-build-test cycle without the interactive subsystem.

1.3. Exercises

The provided MinHS main program can only produce very simple reports. Think about how you would add another one.

The MinHS language given here has a let binding mechanism, involving its AST constructor Let. The let-binding binds a list of names to expressions, and each name bound may also take a list of parameters. In the MinHS lecture we said we had no need for a let expression since it can be encoded via recfun.

Exercise 1: We have not yet specified the meaning of a let expression with multiple bindings. Is this important? Do any of the example programs contain multiple bindings (more than 1) in a Let construct in the parsed abstract syntax? In fact, how many let constructs are there in all the examples?

Exercise 2: What is the concrete syntax corresponding to an abstract syntax Let construct with multiple bindings? There are multiple ways you could figure this out, can you think of more than one?

Exercise 3: As a more substantial exercise, can you write a Haskell program that compiles from MinHS syntax to MinHS syntax and eliminates the Let construct? You can ignore cases involving multiple bindings for now. Can you add a simple report that confirms that programs that were type correct before are still type correct after? It would be nice to check that the programs evaluate to the same thing, but that will have to wait for Assignment 1.

These exercises are optional and will not be marked.

1.4. Feedback

This is a demo exercise. The goal is (a) to show you the MinHS system (b) to make sure that the build process works and (c) to get you thinking about transformations of the MinHS AST and their semantics.

Have any interesting experiences or thoughts about the exercises? There is a forum category set up for this demo assignment, feel free to share your thoughts there, but try not to "spoil" the answers to the above questions.

2025-12-05 Fri 11:50

Announcements RSS