Module 19: Disco
In this final module, you will work together to explore and modify a more complex language implementation. Unlike previous modules, for this module you will all work togther as a class, and you will not receive a grade. I will sit in the back to observe, and only answer questions in a dire emergency. Think of it as an ungraded, group final exam.
Start by picking a driver who has stack installed. The driver should project their screen so everyone can see.
Installing
Install the
stacktool by following the installation instructions. (Only the driver needs to havestackinstalled, but others may install it too if they wish.)Clone the
discorepository from GitHub:git clone https://github.com/disco-lang/disco.gitBuild it with
stack:cd disco stack build --fast
The final step might take a while as stack automatically downloads and compiles all the dependencies.
Familiarization
While you are waiting for stack build:
Look through the examples in the
examplesdirectory to get a basic sense for the language (some of the examples are better than others).Look through the code in the
srcdirectory to get a basic idea of what is there.Make a new file in the
examplesdirectory calledgcd.disco. Define a function calledgcdwhich computes the greatest common divisor of two natural numbers. (Recall that thegcdofnwith0is alwaysn, and otherwise thegcdofaandbis equal to thegcdofbanda mod b.)Hopefully by this point
stack buildhas finished. Runstack exec discoto run the REPL.Load your file with
:load examples/gcd.discoand test yourgcdfunction.
Trial by fire
Suppose we wanted to instead have built-in support for gcd in Disco. Add an infix gcd operator to the language! That is, once you are done, it should be possible to do this:
stack exec disco
Disco> 12 gcd 42
6
Some suggestions:
Run
stack build --file-watch --fastin a terminal, which will try to automatically rebuild the REPL every time you edit one of the source files. In another terminal, you can run the Disco REPL. Note you will have to quit (:quit) and restart (stack exec disco) the REPL to incorporate the latest changes.I suggest starting by making an appropriate change to
src/Disco/AST/Surface.hs.After making each change, re-run the REPL and try computing a
gcd. It will probably crash or otherwise not work, but the manner in which it breaks may give you a good idea of what to tackle next.Remember to work together! Feel free to switch drivers, and use non-drivers’ computers to look up other information, keep key definitions on the screen for reference, etc.