Closed nrnrnr closed 7 months ago
else wrong
all the time, does reaching fi
imply wrong
? i.e. we avoid generating the final else wrong
branch and say if control reaches past the last branch in an if-fi
or cond
structure, we generate wrong
? Semi-formal translation:
In P:
case scrutinee of
P1 ... Pn -> a
...
==
V-style if-else
:
if (exists? P1 ... Pn. scrutinee = P1 ... Pn) then a
else if ...
else wrong
==
Now with cond
:
(cond
(exists? P1 ... Pn. scrutinee = P1 ... Pn a)
...
else wrong)
// note: as asked above, since our cond form is to AVOID "else wrong",
// I believe we don't want this last branch as explicit?
==
Finally, Dijkstra's if
:
if
(exists? P1 ... Pn. scrutinee = P1 ... Pn -> a)
(truthy value) (unification problem -> res)
fi
--- getting here yields WRONG
- Wrote this. It's only as right as the first one. Question- since we want to avoid writing
else wrong
all the time, does reachingfi
implywrong
? i.e. we avoid generating the finalelse wrong
branch and say if control reaches past the last branch in anif-fi
orcond
structure, we generatewrong
?
Yes. Our if ... fi
is just a better concrete syntax for cond
. I recommend you look at the desugaring for cond
on page 164, BPC. Which I see is missing a bracket.
I also recommend you look at the laws and semantics for case
expressions in Chapter 9 Chapter 8.
Read BPC (I believe it's chapter 8; 9 is molecule). Tired after intro and other homework, so posting real updates tomorrow.
Got some translations and the beginnings of code. Tomorrow's project to make good enough to post.
Here are some possible translations:
cond
-like desugaringif ... -> ... [X] ... -> ... fi
Note: for
P
take thecase
form of μML (BPC, chapter 9)