Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Add explicit clone support to do-notation - #7

Merged
bodil merged 3 commits into
bodil:masterfrom
soulsource:feature/explicit-clone-in-run
Apr 13, 2023
Merged

bodil merged 3 commits into
bodil:masterfrom
soulsource:feature/explicit-clone-in-run

Conversation

@soulsource

Copy link
Copy Markdown
Contributor

This is the implementation of explicit clones in do-notation, as discussed in issue #6. The issue should be resolved by this.

To reduce the amount of code duplication, the match arms in the macro that do not contain explicit clone parameters forward to those that contain them.

I really hope the macro doesn't have any ambiguity now. I think it should be fine, but my experience with macros in Rust is still limited, so it is possible that I'm overlooking something.

This enables the user to explicitly clone values in do-notation. That is
needed because otherwise one would not be able to carry such values
along in do-notation for more than 2 statements.

The reason is the parameter of `bind()`, which has to be `Fn`. If that
parameter could be `FnOnce`, this issue would not exist, because a clean
chain of moves would be possible. However, limiting the parameter for
`bind()` would prevent implementing `Bind` for many structures that
should be Monads, for instance `Vec`.

With `bind()` taking `Fn`, the only option is to clone the
to-be-captured values, either implicitly if they are `Copy`, or
explicitly. This could of course be done before, but the syntax was
convoluted. This change simplifies the syntax to a list of
variables that one can add in front of the individual statements in
do-notation.
@soulsource

Copy link
Copy Markdown
Contributor Author

As far as I can tell, the failing tests fail on master too.

@bodil
bodil merged commit 9f48c7d into bodil:master Apr 13, 2023
@bodil

bodil commented Apr 13, 2023

Copy link
Copy Markdown
Owner

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants