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

[ fix #758 ] desugar non-binding sequencing in do blocks to (>>) #1095

Merged
merged 12 commits into from
Feb 24, 2021

Conversation

gallais
Copy link
Member

@gallais gallais commented Feb 20, 2021

Instead of desugaring do blocks using >>= only i.e. elaborating

do x <- p
   q
   r

to

p >>= \ x => q >>= \ _ => r

we make sure that non-binding sequencing uses (>>) and get:

p >>= \ x => q >> r

This allows us to have a special >> that, for instance, is compatible
with a linear bind by enforcing that its first argument returns (),
a value easily consumed.

The silent expansion of

```idris
do p
   q
```

to

```
p >>= \ _ => q
```

acted like a pattern-synonym when building these grammars and thus
did not get in the way of termination / productivity checking. When
we introduce (>>), it breaks this convenient feature and to recover
it we need to introduce new constructors.

It's unfortunate but not too much trouble.
@gallais gallais marked this pull request as ready for review February 20, 2021 12:17
@gallais gallais changed the title [ fix #758 ] desugar to (>>) [ fix #758 ] desugar non-binding sequencing in do blocks to (>>) Feb 20, 2021
@andrevidela
Copy link
Collaborator

This seems like quite a disruptive change, doesn't it break backward compatibility too? Not having to bind resulting values from in do block was a nice quality of life feature that we lose.

@gallais
Copy link
Member Author

gallais commented Feb 21, 2021

doesn't it break backward compatibility too?

Yes. On the other hand, it helps inference and you get a warning when
you're silently throwing away a non-unit result (you can use ignore
to throw it away explicitly).

@gallais gallais merged commit d2eeb7c into idris-lang:master Feb 24, 2021
@gallais gallais deleted the issue758 branch February 24, 2021 11:07
alexhumphreys pushed a commit to alexhumphreys/idrall that referenced this pull request Mar 9, 2021
includes fixes for unbound returns in `do` blocks, and some missing Lazy
annotations.

The `do` block fixes were needed after
idris-lang/Idris2#1095 was merged. could also
use `ignore` for this rather than `_ <- foo`

Signed-off-by: Alex Humphreys <[email protected]>
trevarj added a commit to trevarj/Idris2 that referenced this pull request Jan 30, 2022
There is a difference between idris1 and idris2 which breaks backwards compatibility when trying to implement `(>>=)` to use `do` notation for a custom type. See idris-lang#1095 for details.
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.

Linear functions lose their linearity annotation when wrapped in a monad
3 participants