Skip to content

Conversation

@ivg
Copy link
Member

@ivg ivg commented Nov 9, 2020

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)

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)
```
@ivg ivg merged commit 874454e into BinaryAnalysisPlatform:master Nov 10, 2020
@ivg ivg deleted the add-bindops-to-monads branch December 1, 2021 19:14
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.

1 participant