[#847] Refactor typechecker monad
Description
Problem: 'TypeCheck' &c monads are a) using 'State' where a 'Reader' would be enough and b) are using multiple awkward lifts to handle nested reader stacks.
Solution: Implement 'MultiReaderT', a poor man's extensible reader effects via nested 'ReaderT' using recursive closed type families and Peano arithmetic. Replace 'State' with 'ReaderT'; reorder the stack to put all readers on top; use 'MultiReaderT' machinery to simplify accessing reader envs.
Other options considered and rejected:
- Use
vinyl
records as the reader environment. This would work, but fiddling with subtyping constraints with the simplified subsumption seemed like a lot of menial work. - Use extensible records via a type parameter. This would work and require less type family magic, but at the cost of record field access being more awkward.
Related issue(s)
Resolves #847 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.
Edited by Nikolay Yakimov