3 ms·
Most of that code (the part between the `:` and the `=`) is just the type annotation, which actually acts as documentation :) My guess in this case is that get
by ufo 9y ago
Most of that code (the part between the `:` and the `=`) is just the type annotation, which actually acts as documentation :)
My guess in this case is that get_internal is a function that receives two parameters (a map with keys of type `a` and values of type `b`, and a key of type `a`) and returns a value of type `b` or `undefined`, if the key is missing. The return is wrapped in an option type so you don't mix the `b`s with the `undefined`s.
That said, this is a very weird example to pick because the actual implementation of the function is not in this file. Assuming that in Reason the @@ means the same as in Ocaml, that `@@` is placeholder that tells the code preprocessor where to insert the actual code for the implementation of `get`. The actual logic for the get function would be in the preprocessor.
- yawaramin 9y agoThe `[@@bs.get]` attribute tells the BuckleScript compiler (Reason's JavaScript backend) to emit a JavaScript object 'get' operation wherever its corresponding function (in this case `get_internal`) is used.
- AlexCoventry 9y ago> in Ocaml, that `@@` is placeholder that tells the code preprocessor where to insert the actual code for the implementation of `get`. Where's the documentation for this? I'm only familiar with `@@` as a low-precedence no-op operator which helps to cut down on parentheses.
- ufo 9y agoThe `[@@blah]` syntax refers to the extension-points feature that was introduced in Ocaml 4.02: https://whitequark.org/blog/2014/04/16/a-guide-to-extension-points-in-ocaml/ https://whitequark.org/blog/2014/04/16/a-guide-to-extension-... https://blog.janestreet.com/extension-points-or-how-ocaml-is-becoming-more-like-lisp/ https://blog.janestreet.com/extension-points-or-how-ocaml-is... These can be used to do the sort of metaprogramming that people used to do with camlp4. If you want to search more, the other keyword for googling would be "ppx".
- AlexCoventry 9y agoThanks.