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

implement monadic syntax sugar #1326

Open
bobzhang opened this issue Mar 7, 2017 · 3 comments

Comments

@bobzhang
Copy link
Member

commented Mar 7, 2017

see discussions in #1214

after some research, below is the syntax I think will be great and extensible in the future

let [@bs] v0  = promise0 in  (* default to Promise.bind *)
let [@bs] v1 = promise1 in 
let [@bs Option] v2 = optionl2 in  (* now default to Option.bind *)
let [@bs ] v3 = optional3 in 
let [@bs Promise] v4 = promise4 in (* back to promise *)
let [@bs error] v5 = error_handling in  (* here bind to Promise.catch *)
...  

We chose attributes instead of extension (like janestreet let%bind) because attributes allow payload for more customization later

todo:

research on semantics of let .. and

@yawaramin

This comment has been minimized.

Copy link
Contributor

commented Apr 7, 2019

Bob, can we do something like what dune is doing and backport the new let* syntax? From that post:

The shim preprocessor converts bindings operators to OCaml identifiers of the form let__XXX and and__XXX. For instance, let+* is translated to let__plus_star. So you must make sure to not use such identifiers in your code.

I imagine this would be something like let$plus$star in BuckleScript output JS? We could have this shim in bsppx and get rid of it once BuckleScript lands 4.08+.

@utkarshkukreti

This comment has been minimized.

Copy link
Contributor

commented Jun 15, 2019

OCaml 4.08.0 is out. Would be really cool to have what @yawaramin suggested now!

@bobzhang

This comment has been minimized.

Copy link
Member Author

commented Jun 21, 2019

There are some nice features in 4.08, so we may target 4.08.1 sooner than original timeline, we will see in next few months

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.