Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Alain
Alain

Posted on

     

Using `let.opt` in Rescript with latest Reason/OCaml

This is your Reason(let.opt) definition.

let (let.opt) = (x, f) =>  switch (x) {  | None => None  | Some(x) => f(x)  };let (and.opt) = (a, b) =>  switch (a, b) {  | (Some(a), Some(b)) => Some((a, b))  | _ => None  };let z = (a,b)=> {  let.opt a = a  and.opt b = b;  Some(a + b);};
Enter fullscreen modeExit fullscreen mode

This is your Rescript file onocaml@4.12.0:

//Demo.resleta=Some(10);letb=Some(3);Js.log2("using ocaml 4.12 compiled reasonml let.opt in Rescript",Opts.z(a,b));
Enter fullscreen modeExit fullscreen mode

Here is a gist.

Here is a project you can run:

GitHub logo idkjs / letop-rescript

using (let.opt) style in rescript

Resources:https://github.com/ocaml/ocaml/pull/1947
Melange:https://github.com/melange-re/melange
Rescript:https://rescript-lang.org/
Discord:https://discord.gg/KAJBzYaf

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
danielo515 profile image
Daniel Rodríguez Rivero
  • Joined

Do you mean explaining how is this applied ? And expects a and b, and returns a tuple, which I don’t see used in z nor in the first letop. Can you expand further ?

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromAlain

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp