Last active
August 21, 2019 06:06
-
-
Save gaku-sei/0a79e5a302a10999bc8ad4beb27faa95 to your computer and use it in GitHub Desktop.
Some remarks on Reasonml "object" like types
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
/// Records | |
// Straigth forward, use this when an object remains in the BuckleScript realm | |
type record = { foo: int }; | |
// Will _not_ compile to a JS object (at least, until some pr like https://github.com/BuckleScript/bucklescript/pull/3741 are merged) | |
let record: record = { foo: 42 }; | |
/// OCaml objects | |
// Probably no real need for this | |
type obj = {. foo: int }; // or {.. foo: int } for open object */ | |
// Also, it's a bit verbose | |
let obj: obj = { | |
pub foo = 42; | |
}; | |
/// JS Objects | |
// Super useful since it compiles to a JS object | |
// Could be used in Ocaml to avoid unnecessary conversions | |
type jsObj = {. "foo": int }; // or {.. "foo": int }; for open JS object */ | |
// Compiles to a JS object as expected | |
let jsObj: jsObj = { "foo": 42 }; | |
// You can even use free form JS objects! | |
let crazyJsObj = { "bar": 42 }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment