-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds binding operators to the monads library (#1234)
Instead of extending the `Syntax` module of the `Monad.S` and `Monad.S2` interface, which will break the interfaces, we add a new module `Let` which includes binding operators for Monadic and applicative interfaces (`let*`/`and*` and `let+`/`and+` correspondingly). That means that in order to be able to use the monadic operators for the monad `Example` we need to open either `Example` or `Example.Let` first, so we can write ``` open Example.Let let example x y = let* r = compute x in let+ s = compute y in r + s ``` instead of the old style with `fun`, ``` open Example.Syntax let example x y = compute x >>= fun r -> compute y >>| fun s -> r + s ``` Parallel binding is provided via the `(and*)` and `(and+)` operators, so it is possible to write ``` open Example.Let let example x y = let* r = compute x in and* s = compute y in Example.return (r + s) ```
- Loading branch information
Showing
3 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters