Assignment 7: Monads and more functors
In this assignment you will write a functor and a monad module, and then you’ll use the module to refactor some stateful OCaml code to use a state monad.
The file structure
- Use this zip file for your assignment.
- Provided are three
.mlifilessrc/fpse_monad.mli,src/state_monad.mli, andsrc/stack_monad.mli. Look at the files in this order, and implement an appropriately named.mlfile for each of them.- Do not edit the
.mlifiles. You will not submit them. - Note you may not use
Coreinsrc/fpse_monad.ml. You will not submit adunefile forsrc/, so you cannot add any libraries to what is in the givendunefile.
- Do not edit the
- A library using your
Stack_monadmodule is insrc/main.ml. See that file and follow the instructions to complete the implementation. - There is an empty
test/tests.mlin which you will put your tests.- You won’t be graded on your tests.
- You need to fill in the
test/dunefile to run your tests.
- Answer a quick discussion question in
discussion.txt.
Submission and Grading
- As usual, run a final
dune clean; dune buildand then upload_build/default/assignment7.zipto Gradescope. - You will be graded with an autograder and on your discussion question.
- We will check that you actually used the monad in your implementation instead of cheating with mutation.