I am reading about Semantics of Programming Languages and here is an attempt to code Racket
to parse and interpret toy languages. More details will be added.
The code here is not the final version but it compiles. It shows the progress made as I learn the nuances of
Racket and types.
Semantics of a simple language
I use typed Racket and my IDE is Doom Emacs. But I may also code OCaml. The code here is ported from SML/NJ.
Pre-requisites
I have mentioned what was useful for me when I attempted to learn the subject.
Knowledge of SML because some key books use OCaml or SML.
Ability to understand basic proof techniques. This book helped me even though I haven’t finished it.
Professor David Solow’s lectures are available and he clearly explains the steps involved in writing and
reading condensed proofs. Highly recommended.
Attempt 1
This does not use Abstract Data Types.
This makes the pattern matchers hard to implement and reason about.
Attempt 2
I had to use a macro and create a proper ADT(Abstract Data Type ) to proceed. The previous
code was too verbose. The ADT makes the pattern matcher easier to implement.
The current version is in my Git.
But this code is not complete. It has some serious faults in as far as the types and patterns are
concerned. So I decided to pay close attention to the types and compare the SML output and the
output of my Racket code.
Even though I am porting from SML to Racket I don’t use idiomatic Racket everywhere. Parts of
the code may not seem coherent but I ensure that the basic unit tests pass.
Final Attempt
Fixed may type annotation bugs
Fixed all the patterns after reading the documentation.
Fixed most of the logic bugs. The code still doesn’t behave exactly like the SML
code.
This code is only one part of the attempt to learn and implement types and toy languages.