Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2176

How do you writing bindings today?

$
0
0

Hi there,

Recently, I have been asking myself how others deal with bindings.
Since BuckleScript, bindings of API like this :

const someLib = {
  exec: () => 4
}
someLib.exec()

are written in OCaml style with module t like this with @send :

module SomeLib = {
  type t

  @module("xx")
  external instance: t = "default"
  @send
  external exec: (t, unit) => int = "exec"
}

SomeLib.instance->SomeLib.exec()

But today we can write JS like bindings like this :

type lib = {
  exec: unit => int
}

@module("xx")
external myLib: lib = "default"

myLib.exec()

The JavaScript output will be the same with no cost but the usage feels pretty different. Should we enforce more a pattern than another ? :thinking:


Viewing all articles
Browse latest Browse all 2176

Trending Articles