Skip to content

Instantly share code, notes, and snippets.

@skiadas
Created March 11, 2016 01:31
Show Gist options
  • Save skiadas/da6290be8fd7812698d3 to your computer and use it in GitHub Desktop.
Save skiadas/da6290be8fd7812698d3 to your computer and use it in GitHub Desktop.

The desugarer

Most of this will make sense once you hit the "conditionals" part of the project.

It is important to understand how the desugarer differs from the interpreter. Think of the desugarer as a "program transformation". You give it a program in one form, and it turns it into another form. It does NO evaluation of the program, only a syntactic transformation.

For example if you recall in the early days we talked about the expression: e1 or e2 and how we can instead get the same thing going with if statements:

if e1
then true
else e2

You could also go with:

if e1
then true
else if e2
     then true
     else false

(As a parenthetical, make sure you understand how these two have slightly different semantics in a language that doesn't require the type of the test expression to actually be boolean, e.g. in Javascript.)

Basically this is what the desugarer would do: It would take the e1 or e2 expression and rewrite it as an if-then-else. It does not care at all if e1 and e2 are true or false, or even whether they would produce a type error or something. It just transforms the program.

In your particular case, the desugarer should turn an OrS expression into a combination of IfCs with some BoolCs thrown in when needed. But it would effectively just perform the above rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment