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
stack
tool by following the installation instructions. (Only the driver needs to havestack
installed, but others may install it too if they wish.)Clone the
disco
repository from GitHub:git clone https://github.com/disco-lang/disco.git
Build 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
examples
directory to get a basic sense for the language (some of the examples are better than others).Look through the code in the
src
directory to get a basic idea of what is there.Make a new file in the
examples
directory calledgcd.disco
. Define a function calledgcd
which computes the greatest common divisor of two natural numbers. (Recall that thegcd
ofn
with0
is alwaysn
, and otherwise thegcd
ofa
andb
is equal to thegcd
ofb
anda mod b
.)Hopefully by this point
stack build
has finished. Runstack exec disco
to run the REPL.Load your file with
:load examples/gcd.disco
and test yourgcd
function.
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 --fast
in 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.