Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

viktoriia-fomina
Copy link
Owner

No description provided.

let rec isFreeVar expression var =
match expression with
| Variable x -> x = var
| Abstr(vr, term) -> vr = var || (isFreeVar term var)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мм, переменная за лямбдой разве входит свободно? Наоборот, она связанная и должна исключиться из множества свободных в term переменных. Наоборот же, если vr = var, то false

Copy link
Owner Author

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)

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это лучше на разных строчках записать.

Comment on lines 40 to 42
| Applic(l, r) -> match reduceLeftOuter l with
| Abstr(var, lmd) -> betaReduction (substitute lmd var r)
| var -> Applic(betaReduction var, betaReduction r)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это подозрительно похоже на reduceLeftOuter, и неспроста --- это и есть шаг редукции, и тут, и там

Copy link

@yurii-litvinov yurii-litvinov left a 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну, некоторый копипаст между reduceLeftOuter и этим куском кода остался, но ладно

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants