{"id":13726389,"url":"https://github.com/glennsl/bucklescript-ffi-cheatsheet","last_synced_at":"2025-07-04T18:33:07.466Z","repository":{"id":72537215,"uuid":"89620944","full_name":"glennsl/bucklescript-ffi-cheatsheet","owner":"glennsl","description":null,"archived":false,"fork":false,"pushed_at":"2019-08-25T17:26:25.000Z","size":7,"stargazers_count":163,"open_issues_count":0,"forks_count":7,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-01-22T00:36:25.013Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glennsl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-04-27T16:59:35.000Z","updated_at":"2024-09-22T05:16:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd0d873d-727e-4f08-b81d-fa911242ba79","html_url":"https://github.com/glennsl/bucklescript-ffi-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Fbucklescript-ffi-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Fbucklescript-ffi-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Fbucklescript-ffi-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Fbucklescript-ffi-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glennsl","download_url":"https://codeload.github.com/glennsl/bucklescript-ffi-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713402,"owners_count":20335566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:03:02.687Z","updated_at":"2025-03-15T09:42:09.770Z","avatar_url":"https://github.com/glennsl.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# BuckleScript FFI cheatsheet\n\nNOTE: The translations given here might not be literally correct. The output will in some instances have been simplified slightly to improve clarity.\n\n## Basic\n\n### [bs.val](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_global_value_code_bs_val_code)\n```ml\n(* ml *)\nexternal f : 'a -\u003e 'b -\u003e 'ret = \"\" [@@bs.val]\n\nlet ret = f a b\n```\n```reason\n/* re */\n[@bs.val] external f : ('a, 'b) =\u003e 'ret = \"\";\n\nlet ret = f(a, b);\n```\n```js\n// js\nvar ret = f(a, b);\n```\n\n### [bs.get](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_getter_setter_code_bs_get_code_code_bs_set_code)\n```ml\n(* ml *)\nexternal f : 'self -\u003e 'ret = \"\" [@@bs.get]\n\nlet ret = f self\n```\n```reason\n/* re */\n[@bs.get] external f : 'self =\u003e 'ret = \"\";\n\nlet ret = f(self);\n```\n```js\n// js\nvar ret = self.f;\n```\n\n### [bs.set](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_getter_setter_code_bs_get_code_code_bs_set_code)\n```ml\n(* ml *)\nexternal f : 'self -\u003e 'a -\u003e 'ret = \"\" [@@bs.set]\n\nlet ret = f self a\n```\n```reason\n/* re */\n[@bs.set] external f : ('self, 'a) =\u003e 'ret = \"\";\n\nlet ret = f(self, a);\n```\n```js\n// js\nvar ret = self.f = a;\n```\n\n### [bs.send](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_method_code_bs_send_code_code_bs_send_pipe_code)\n```ml\n(* ml *)\nexternal f : 'self -\u003e 'a -\u003e 'b -\u003e 'ret = \"\" [@@bs.send]\n\nlet ret = f self a b\n```\n```reason\n/* re */\n[@bs.send] external f : ('self, 'a, 'b) =\u003e 'ret = \"\";\n\nlet ret = f(self, a, b);\n```\n```js\n// js\nvar ret = self.f(a, b);\n```\n\n### [bs.send.pipe](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_method_code_bs_send_code_code_bs_send_pipe_code)\n```ml\n(* ml *)\nexternal f : 'a -\u003e 'b -\u003e 'ret = \"\" [@@bs.send.pipe: 'self]\n\nlet ret = f a b self\n(* or *)\nlet ret = self |\u003e f a b\n```\n```reason\n/* re */\n[@bs.send.pipe: 'self] external f : ('a, 'b) =\u003e 'ret = \"\";\n\nlet ret = f(a, b, self);\n/* or */\nlet ret = self |\u003e f(a, b);\n```\n```js\n// js\nvar ret = self.f(a, b);\n```\n\n### [bs.new](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_javascript_constructor_code_bs_new_code)\n```ml\n(* ml *)\nexternal f : unit -\u003e 'ret = \"\" [@@bs.new]\n\nlet ret = f ()\n```\n```reason\n/* re */\n[@bs.new] external f : unit =\u003e 'ret = \"\";\n\nlet ret = f();\n```\n```js\n// js\nvar ret = new f();\n```\n\n### [bs.module](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_a_value_from_a_module_code_bs_module_code)\n```ml\n(* ml *)\nexternal f : unit -\u003e unit = \"\" [@@bs.module \"m\"]\n\nlet _ = f ()\n```\n```reason\n/* re */\n[@bs.module \"m\"] external f : unit =\u003e unit = \"\";\n\nf();\n```\n```js\n// js\nvar m = require('m');\nm.f();\n```\n\n### [bs.get_index](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_dynamic_key_access_set_code_bs_set_index_code_code_bs_get_index_code)\n```ml\n(* ml *)\nexternal f : 'self -\u003e 'key -\u003e 'ret = \"\" [@@bs.get_index]\n\nlet ret = f self key\n```\n```reason\n/* re */\n[@bs.get_index] external f : ('self, 'key) =\u003e 'ret = \"\";\n\nlet ret = f(self, key);\n```\n```js\n// js\nvar ret = self[key];\n```\n\n### [bs.set_index](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_dynamic_key_access_set_code_bs_set_index_code_code_bs_get_index_code)\n```ml\n(* ml *)\nexternal f : 'self -\u003e 'key -\u003e 'a -\u003e 'ret = \"\" [@@bs.set_index]\n\nlet ret = f self key a\n```\n```reason\n/* re */\n[@bs.set_index] external f : ('self, 'key, 'a) =\u003e 'ret = \"\";\n\nlet ret = f(self, key, a);\n```\n```js\n// js\nvar ret = self[key] = a;\n```\n\n\n## Advanced\n\n### [bs.splice](https://bucklescript.github.io/bucklescript/Manual.html#_splice_calling_convention_bs_splice)\n```ml\n(* ml *)\nexternal f : 'a -\u003e 'b array -\u003e 'ret = \"\" [@@bs.val] [@@bs.splice]\n\nlet ret = f a [|b1; b2; b3|]\n```\n```reason\n/* re */\n[@bs.val] [@bs.splice] external f : ('a, array('b)) =\u003e 'ret = \"\";\n\nlet ret = f(a, [|b1, b2, b3|]);\n```\n```js\n// js\nvar ret = f(a, b1, b2, b3);\n```\n\n### [bs.scope](https://bucklescript.github.io/bucklescript/Manual.html#_scoped_values_bs_scope_since_1_7_2)\n```ml\n(* ml *)\nexternal f : unit -\u003e unit = \"\" [@@bs.val] [@@bs.scope \"a\", \"b\"]\n\nlet _ = f ()\n```\n```reason\n/* re */\n[@bs.val] [@bs.scope (\"a\", \"b\")] external f : unit =\u003e unit = \"\";\n\nf();\n```\n```js\n// js\na.b.f();\n```\n\n### [bs.return](https://bucklescript.github.io/bucklescript/Manual.html#_return_value_checking_since_1_5_1)\n\n### [bs.obj](https://bucklescript.github.io/bucklescript/Manual.html#_create_js_objects_using_external)\n\n### [bs.as](https://bucklescript.github.io/bucklescript/Manual.html#_fixed_arguments)\n```ml\n(* ml *)\nexternal f : 'a -\u003e (_ [@bs.as \"b\"]) -\u003e 'c -\u003e unit = \"\" [@@bs.val]\n\nlet _ = f a c\n```\n```reason\n/* re */\n[@bs.val] external f : ('a, [@bs.as \"b\"] _, 'c) =\u003e unit = \"\";\n\nf(a, c);\n```\n```js\n// js\nf(a, \"b\", c);\n```\n\n### [bs.string](https://bucklescript.github.io/bucklescript/Manual.html#_using_polymorphic_variant_to_model_enums_and_string_types)\n```ml\n(* ml *)\nexternal f : ([`a] [@bs.string]) -\u003e unit = \"\" [@@bs.val]\n\nlet _ = f `a\n```\n```reason\n/* re */\n[@bs.val] external f : ([@bs.string] [`a]) =\u003e unit = \"\";\n\nf(`a);\n```\n```js\n// js\nf(\"a\");\n```\n\n### [bs.int](https://bucklescript.github.io/bucklescript/Manual.html#_using_polymorphic_variant_to_model_enums_and_string_types)\n```ml\n(* ml *)\nexternal f : ([`a] [@bs.int]) -\u003e unit = \"\" [@@bs.val]\n\nlet _ = f `a\n```\n```reason\n/* re */\n[@bs.val] external f : ([@bs.int] [`a]) =\u003e unit = \"\";\n\nf(`a);\n```\n```js\n// js\nf(0);\n```\n\n### [bs.unwrap](https://bucklescript.github.io/bucklescript/Manual.html#_using_polymorphic_variant_to_model_arguments_of_multiple_possible_types_since_1_8_3)\n```ml\n(* ml *)\nexternal f : ([`int of int] [@bs.unwrap]) -\u003e unit = \"\" [@@bs.val]\n\nlet _ = f (`int 42)\n```\n```reason\n/* re */\n[@bs.val] external f : ([@bs.unwrap] [`int(int)]) =\u003e unit = \"\";\n\nf(`int(42));\n```\n```js\n// js\nf(42);\n```\n\n### [bs.ignore](https://bucklescript.github.io/bucklescript/Manual.html#_phantom_arguments_and_ad_hoc_polymorphism)\n```ml\n(* ml *)\nexternal f : 'a -\u003e ('b [@bs.ignore]) -\u003e 'c -\u003e unit = \"\" [@@bs.val]\n\nlet _ = f a b c\n```\n```reason\n/* re */\n[@bs.val] external f : ('a, [@bs.ignore] 'b, 'c) =\u003e unit = \"\";\n\nf(a, b, c);\n```\n```js\n// js\nf(a, c);\n```\n\n### [bs](https://bucklescript.github.io/bucklescript/Manual.html#__bs_for_explicit_uncurried_callback)\n### [bs.uncurry](https://bucklescript.github.io/bucklescript/Manual.html#__bs_uncurry_for_implicit_uncurried_callback_since_1_5_0)\n### [bs.this](https://bucklescript.github.io/bucklescript/Manual.html#_bindings_to_code_this_code_based_callbacks_bs_this)\n### [bs.open](https://bucklescript.github.io/bucklescript/Manual.html#__code_bs_open_code_type_safe_external_data_source_handling_since_1_7_0)\n\n## Extensions\n\n### [bs.re](https://bucklescript.github.io/bucklescript/Manual.html#_regex_support)\n```ml\n(* ml *)\nlet re = [%re \"/na/gi\"]\n```\n```reason\n/* re */\nlet re = [%re \"/na/gi\"];\n```\n```js\n// js\nvar re = /na/gi;\n```\n\n### [bs.obj](https://bucklescript.github.io/bucklescript/Manual.html#_create_js_objects_using_bs_obj)\n```ml\n(* ml *)\nlet obj = [%obj { property = \"value\" }]\n```\n```reason\n/* re */\nlet obj = [%obj { property: \"value\" }];\n/* or */\nlet obj = { \"property\": \"value\" };\n```\n```js\n// js\nvar obj = {\n  property: \"value\"\n};\n```\n\n### [bs.raw](https://bucklescript.github.io/bucklescript/Manual.html#_embedding_raw_js_code_as_statements)\n\n#### Expression\n\n```ml\n(* ml *)\nlet raw = [%raw \"1 + 2 == 3\"]\n```\n```reason\n/* re */\nlet raw = [%raw \"1 + 2 == 3\"];\n```\n```js\n// js\nvar raw = (1 + 2 == 3);\n```\n\n#### Function\n\n```ml\n(* ml *)\nlet myFunction = [%raw fun a b -\u003e \"return a + b;\"];\n```\n```reason\n/* re */\nlet myFunction = [%raw (a, b) =\u003e \"return a + b;\"];\n```\n```js\n// js\nfunction myFunction (a, b) { return a + b; };\n```\n\n#### Block\n\n```ml\n(* ml *)\n[%%raw {|\n  var a = 1;\n  var b = a + 2;\n|}]\n```\n```reason\n/* re */\n[%%raw {|\n  var a = 1;\n  var b = a + 2;\n|}];\n```\n```js\n// js\nvar a = 1;\nvar b = a + 2;\n```\n\n### [bs.debugger](https://bucklescript.github.io/bucklescript/Manual.html#_debugger_support)\n```ml\n(* ml *)\n[%debugger]\n```\n```reason\n/* re */\n[%debugger];\n```\n```js\n// js\ndebugger;\n```\n\n### [bs.external](https://bucklescript.github.io/bucklescript/Manual.html#_detect_global_variable_existence_code_bs_external_code_since_1_5_1)\n### [bs.node](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_nodejs_special_variables_bs_node)\n\n## JS Objects\n\n### [Js.t](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_js_objects)\n### [##](https://bucklescript.github.io/bucklescript/Manual.html#_binding_to_js_objects)\n### [class type ... end \\[@bs\\]](https://bucklescript.github.io/bucklescript/Manual.html#_complex_object_type)\n### [#=](https://bucklescript.github.io/bucklescript/Manual.html#_how_to_consume_js_property_and_methods)\n### [bs.get](https://bucklescript.github.io/bucklescript/Manual.html#_getter_setter_annotation_to_js_properties)\n### [bs.set](https://bucklescript.github.io/bucklescript/Manual.html#_getter_setter_annotation_to_js_properties)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsl%2Fbucklescript-ffi-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglennsl%2Fbucklescript-ffi-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsl%2Fbucklescript-ffi-cheatsheet/lists"}