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

Evaluation order of side effect within let bindings #3

Open
finnteegen opened this issue Jan 28, 2021 · 5 comments
Open

Evaluation order of side effect within let bindings #3

finnteegen opened this issue Jan 28, 2021 · 5 comments

Comments

@finnteegen
Copy link
Member

finnteegen commented Jan 28, 2021

I wondered if there is any way to guarantee an evaluation order of side effects within let bindings in an expression like [let {i = 1; _ = putStrLn "Name?"; name = getLine } in name]. Currently, the getLine is executed before the putStrLn (which was not what I intended ^^).

@Ziharrk
Copy link
Member

Ziharrk commented Jan 31, 2021

At the moment, the plugin re-orders let-expressions. This is sometimes required, as can be seen by the following example:

test :: ()
test = let x = print i
               i = (let _ = putStrLn "i" in 1)
          in x

What would you expect for the effect order here?

For simpler cases however, we could make sure that the effect order is top to bottom.
However, that requires a little bit of work.

@finnteegen
Copy link
Member Author

My example originated from the list comprehension example (where the order is hopefully left-to-right as soon as list comprehensions work). Having top-to-bottom for some cases and for others not seems not better to me. I wonder what is the right way to sequence computations then? Singleton let expressions?

@Ziharrk
Copy link
Member

Ziharrk commented Jan 31, 2021

In List comprehensions, at least each let would be its own statement. So it should work left-to-right (except for the fact that ListCompr don't work at all :P).
Sequencing with single-lets would work, but seems a bit tedious.
Maybe we should use top-to-bottom for let whenever possible and emit an error if reordering took place.

@finnteegen
Copy link
Member Author

As long as there is a possiblity to enforce a certain evaluation order, perhaps we do not need to put extra effort into this matter. Also, I do not know how a transformation of let expressions to achieve a certain order of evaluation would effect other Language-Plugins. Since we want a somehow genera approach, it seems sufficient for me to be able to use single-lets (at least I could live with it). We already state that we do have to make sacrifices regarding the syntax. ;)

@Ziharrk
Copy link
Member

Ziharrk commented Feb 1, 2021

We decided to forbid a user from writing let-expressions with either

  • (conservative approach) multiple bindings
  • (user-friendly approach) multiple bindings that were re-ordered due to dependencies between those bindings

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

No branches or pull requests

2 participants