BuckleScript

BuckleScript

  • Docs
  • Try
  • API
  • Community
  • Blog
  • Languages iconEnglish
    • 日本語
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • 中文
    • 繁體中文
    • Help Translate
  • GitHub

›Recent Posts

Recent Posts

  • A story of exception encoding in BuckleScript
  • What's new in release 7.3
  • Generalized uncurry support in BuckleScript 7.3
  • Announcing bs-platform 7.2
  • Loading stdlib from memory

First-class `bs.variadic` Support in the Next Release

March 1, 2019

In previous releases, when a bs.variadic external (previously called bs.splice prior to version 4.08) is present, its tail arguments needed to be applied statically. In other words, the external marked with bs.variadic, when used, requires a literal array:

external join : string array -> string = "join"
[@@bs.module "path"][@@bs.variadic]

let _ = join [|"a"; "b"|] (* this is ok *)
let f b = join b (* compiler error when you try to abstract `join` *)
[@bs.module "path"][@bs.variadic]
external join: array(string) => string = "join"

let _ = join([|"a", "b"|]) /* this is ok */
let f = b => join(b) /* compiler error when you try to abstract `join` */

More importantly, such compilation error was leaky in cases such as this one:

let f = join
let f = join

In the next release, we are going to lift such restriction. You'll be able to call an external marked with bs.variadic with an array reference, not just a literal array.

Caveat: it's unclear how to support such first class bs.variadic call in conjunction with bs.new, so an external declaration that contains both will trigger a compilation error. We'll try to figure out this particular case in the future too.

Recent Posts