Skip to content

Explore user-side variadic functions. #5727

Closed as not planned
Closed as not planned
@cristianoc

Description

@cristianoc

Here's a simple encoding and test:

module Variadic = {
  type t<+'a, 'r>

  let apply: (t<'a, 'r>, array<'a>) => 'r = %raw(`(f, args) => f(...args)`)
  let make: (array<'a> => 'r) => t<'a, 'r> = %raw(`(f) => (...args) => f(args)`)
}

let variadicFun = Variadic.make((a: array<_>) => Js.log(a))
let () = variadicFun->Variadic.apply([3])
let () = variadicFun->Variadic.apply(["a", "b"])

Relevant to the question of whether @variadic at the FFI level is necessary: rescript-lang/rescript-lang.org#572

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleOld issues that went stale

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions