Skip to content

Latest commit

 

History

History
78 lines (62 loc) · 2.96 KB

FAQ.adoc

File metadata and controls

78 lines (62 loc) · 2.96 KB

FAQ

  1. How does IO work in the browser?

    In general, it is very hard to simulate IO in the browser, we recommend users write bindings to NodeJS directly for server side, or use Js.log in client side, see discussions in {issues}/748[#748]

  2. The compiler does not build?

    In production mode, the compiler is a single file in jscomp/bin/compiler.ml. If it is not compiling, make sure you have the right OCaml compiler version. Currently the OCaml compiler is a submodule of BuckleScript. Make sure the exact commit hash matches (we only update the compiler occasionally).

  3. Which version of JavaScript syntax does BuckleScript target?

    BuckleScript targets ES5.

  4. Does BuckleScript work with merlin?

    Yes, you need edit your .merlin file:

    B node_modules/bs-platform/lib/ocaml
    S node_modules/bs-platform/lib/ocaml
    FLG -ppx node_modules/bs-platform/bin/bsppx.exe

    Note there is a upstream fix in Merlin, make sure your merlin is updated.

  5. What polyfills does BuckleScript need?

    • Math.imul: This polyfill is needed for int32 multiplication. BuckleScript provides this by default (when feature detection returns false), no action is required from the user.

    • TypedArray: The TypedArray polyfill is not provided by BuckleScript and it’s the responsibility of the user to bundle the desired polyfill implementation with the BuckleScript generated code.

      The following functions from OCaml stdlib
      require the TypedArray polyfill:
      • Int64.float_of_bits

      • Int64.bits_of_float

      • Int32.float_of_bits

      • Int32.bits_of_float

        Warning

        For the current BuckleScript version, if the user does not bundle the TypedArray polyfill, the JavaScript engine does not support it and user used functions mentioned above, the code will fail at runtime.

  6. Uncurried functions cannot be polymorphic?

    E.g. if you try to do this at toplevel:

let id : ('a -> 'a [@bs]) = ((fun v -> v) [@bs])

You’ll get this dreaded error message

Error: The type of this expression, ([ `Arity_1 of '_a ], '_a) Js.fn,
       contains type variables that cannot be generalized

The issue here isn’t that the function is polymorphic. You can use (and probably have used) polymorphic uncurried functions without any problem as inline callbacks. But you can’t export them. The issue here is the combination of using the uncurried calling convention, polymorphism and exporting (by default). It’s an unfortunate limitation partly due to how OCaml’s type system incorporates side-effects, and partly due to how BuckleScript handles uncurrying. The simplest solution is in most cases to just not export it, by adding an interface to the module. Alternatively, if you really, really need to export it, you can do so in its curried form, and then wrap it in an uncurried lambda at the call site. E.g.:

let _ = map (fun v -> id v [@bs])