Recently, I created a language called Sim to make designing digital circuits simple and fun. Sim looks and feels like a small subset of Elm but has some features unique to circuits. For example, the only types that Sim supports are bit buses, records, and functions. A more advanced feature is the variable bus size:
not a[n] -> [n] = nand a a
Unlike Elm, Sim allows self and mutual recursions:
cascading_not_gates input ->  = let output = or output (not (not input)) in output
s_r_latch s[n] r[n] -> [n] = let q = nand s not_q not_q = nand r q in q
I would really love your feedback and suggestions for Sim.
I also created a WIP accompanying guide for Sim called Crafting Computer. Any feedback for that is also welcome.
Lastly, since I’m a newbie in Hindley Milner type inference, I had trouble inferring the variable bus types mentioned above. All works fine until I call the same function twice in another function. I have yet to figure out a way to uniquely represent the variable bus sizes. For now, I use a combination of:
- the location of the function they are declared in
- the name of the variable size
to identify. However, as you might expect it breaks down when I call the same function twice. Here’s the code for the type checker. An example when type checking breaks down:
test i[i] j[j] k[k] -> [j] = let a = nand i i b = nand j j c = nand k k in b