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

Address name shadowing #1032

Merged
merged 25 commits into from
Nov 30, 2020
Merged

Address name shadowing #1032

merged 25 commits into from
Nov 30, 2020

Conversation

jacereda
Copy link
Contributor

There are some bits here I'm not sure about. I'll try to spot them tomorrow.l

src/Eval.hs Show resolved Hide resolved
src/Eval.hs Show resolved Hide resolved
src/Eval.hs Show resolved Hide resolved
where expandAllInternal xobj =
do (newCtx, expansionResult) <- expand eval ctx xobj
case expansionResult of
Right expanded -> if expanded == xobj
then pure (ctx, Right expanded)
then pure (newCtx, Right expanded)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another instance, which context should we use here?

Copy link
Member

Choose a reason for hiding this comment

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

I think newCtxis correct here

src/Expand.hs Show resolved Hide resolved
@jacereda jacereda requested a review from a team November 29, 2020 18:09
@hellerve
Copy link
Member

Generally, my initial idea was to return the old context if something goes wrong, so that no half-baked bindings etc find their way into there. But I’m not sure whether my approach was ever sound or solid, and I think time has washed away most of it anyway. It seems like either way hasn’t lead to problems, but I think generally being more conservative in what context to choose might be a good idea anyway.

@eriksvedang
Copy link
Collaborator

@hellerve Ah, that makes a lot of sense. (I think I had a similar approach in the early versions of the evaluator too, but forgot about it...)

@eriksvedang
Copy link
Collaborator

@jacereda Let's return the old context in places where there has been an error. Otherwise return latest.

@jacereda
Copy link
Contributor Author

In any case, wouldn't it make sense to ensure a Left comes with the original context instead?

It could also make sense to, say, add some information about the error to the context (number of errors?).

And if the code is refactored at some point to use an Either monad, having Left carry the original context would make sense so you can just write foo >>= bar >>= baz.

@scolsen
Copy link
Contributor

scolsen commented Nov 30, 2020

In any case, wouldn't it make sense to ensure a Left comes with the original context instead?

It could also make sense to, say, add some information about the error to the context (number of errors?).

And if the code is refactored at some point to use an Either monad, having Left carry the original context would make sense so you can just write foo >>= bar >>= baz.

I'd love to move toward using the Either monad for this type of stuff and stick with the Maybe monad for things that can fail but shouldn't necessarily result in errors being reported (such as sequential lookup attempts).

I've also considered just defining a monad implementation for Context since in theory that seems to make a lot of sense (what is context, after all, other than some overarching context in which we are computing (evaluating in this case)?) and would likely simplify much of the context manipulations. But this would require a slight change to the type.

src/Eval.hs Show resolved Hide resolved
src/Eval.hs Show resolved Hide resolved
@eriksvedang
Copy link
Collaborator

eriksvedang commented Nov 30, 2020

In any case, wouldn't it make sense to ensure a Left comes with the original context instead?

@jacereda Yes, that sounds like a better solution. Should it be part of this PR, or another one?

@scolsen Making a custom Context mondad sounds great in the long run.

One thing that we should also plan for a little while thinking about these things is not stopping at the first error, but rather being able to continue complilation in some capacity. So maybe we should just skip ahead to whatever solution is best for doing that, while also cleaning up the code. That should definitely be its own PR though.

@eriksvedang
Copy link
Collaborator

@jacereda You had some comments on returning ctx'' – those should be addressed before merge:ing, right?

@jacereda
Copy link
Contributor Author

@jacereda You had some comments on returning ctx'' – those should be addressed before merge:ing, right?

I still would need confirmation that #1032 (comment) is correct. Looking at expand it seems it can return a mutated context, so I guess this is just a bug that should be fixed, but maybe you prefer to address that in another PR?

@jacereda
Copy link
Contributor Author

Oh, I'll need to rebase because the PR I sent about duplicate members will probably break this.

@jacereda
Copy link
Contributor Author

Rebased.

@eriksvedang
Copy link
Collaborator

@jacereda Alright, I think we're good now?

@jacereda
Copy link
Contributor Author

I think so.

@eriksvedang eriksvedang merged commit 2a94f67 into carp-lang:master Nov 30, 2020
@eriksvedang
Copy link
Collaborator

🎉 🎉 🎉

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.

4 participants