-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lambda interpreter is ready #13
base: master
Are you sure you want to change the base?
Conversation
…/Homework-Semester-4 into LambdaInterpreter
let rec isFreeVar expression var = | ||
match expression with | ||
| Variable x -> x = var | ||
| Abstr(vr, term) -> vr = var || (isFreeVar term var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мм, переменная за лямбдой разве входит свободно? Наоборот, она связанная и должна исключиться из множества свободных в term переменных. Наоборот же, если vr = var, то false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ой, глюк
| Variable x when x = insteadOf -> value | ||
| Variable -> expression | ||
| Abstr(var, lmd) when var = insteadOf -> expression | ||
| Abstr(var, lmd) when not (isFreeVar value var) -> Abstr(var, substitute lmd insteadOf value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А если всё-таки входит свободно? Тоже ведь подстановку надо делать, только после альфа-преобразования
/// Reduce with left outer term. | ||
let rec reduceLeftOuter expression = | ||
match expression with | ||
| Applic(l, r) -> match reduceLeftOuter l with | Abstr(var, lmd) -> substitute lmd var r | var -> Applic(var, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это лучше на разных строчках записать.
| Applic(l, r) -> match reduceLeftOuter l with | ||
| Abstr(var, lmd) -> betaReduction (substitute lmd var r) | ||
| var -> Applic(betaReduction var, betaReduction r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это подозрительно похоже на reduceLeftOuter, и неспроста --- это и есть шаг редукции, и тут, и там
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, теперь всё ок. Зачтена
| Variable -> expression | ||
| Applic(l, r) -> match reduceLeftOuter l with | ||
| Abstr(var, lmd) -> betaReduction (substitute lmd var r) | ||
| var -> Applic(betaReduction var, betaReduction r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну, некоторый копипаст между reduceLeftOuter и этим куском кода остался, но ладно
No description provided.