Questions tagged [bucklescript]

BuckleScript was previously known as a compiler for compiling OCaml to efficient JavaScript code. It has now evolved into the ReScript language. Use the [rescript] tag instead.

BuckleScript was previously known as a back-end for which emits readable, modular and highly performant JavaScript.

On July 2020, BuckleScript (and some parts of the ReasonML syntax) evolved into the ReScript language platform. The term "BuckleScript" is therefore deprecated. Use the tag for BuckleScript specific questions instead.

Useful resources

Related tags

181 questions
3
votes
1 answer

Exporting a list of record to a JavaScript array of object without tags

Say I have the following ReasonML types: type xEntry = {title: string}; type yEntry = {value: int}; type entry = | X(xEntry) | Y(yEntry); and I want to export the following value to the JavaScript side: /* Input */ let value = [ X({title:…
3
votes
1 answer

How does one compile a file with an interface, in BuckleScript?

Without bsb, how does one compile any more than a single unqualified .ml file? $ touch test.ml $ touch test.mli $ bsc test.ml File "test.ml", line 1: Error: Could not find the .cmi file for interface test.mli. I haven't even gotten as far as trying…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
3
votes
2 answers

Convert JSON field to ReasonML variant

I have a JSON structure that contains a field period that can either be an object or a string. I already have the variant ready in my code, and it's working fine: type period = { start: string, end_: string, }; type periodVariant = |…
Bertrand
  • 1,718
  • 2
  • 13
  • 24
3
votes
1 answer

How to use Js.Dict.t type for Js.Dict.get

I am trying to convert some JS to Reason, along the way I need to type a JSON response and also check if a key exists in an object. This is my current code: let api_key = ""; let api_url = "http://ws.audioscrobbler.com/2.0"; let method =…
Fernando Montoya
  • 2,625
  • 1
  • 18
  • 21
3
votes
2 answers

Bindings for functions with options parameter

It is common practice in JavaScript to have a function that takes in an options parameter, like so: function foo({ bar1, bar2, bar3 }) {} foo({ bar1: 5, bar2: 3 }) In Reason/OCaml, one would prefer to use labelled arguments for these functions: let…
David Gomes
  • 5,644
  • 16
  • 60
  • 103
3
votes
2 answers

How can I ask for the type class of a variable?

I'm trying to learn ReasonML, and I'm doing some koans to help me with that task. One of the koans I'm trying to code is about asking for the type of a list after converting it to an array. I know that there are operators in some languages like…
gabrielperales
  • 6,935
  • 1
  • 20
  • 19
3
votes
1 answer

Why the need to call resolve()?

I am looking at an example of Reason at A First Reason React app for Javascript developers And I see that he is calling Js.Promise.resolve when using bs-fetch: RepoData.fetchRepos() |> Js.Promise.then_(repoData => { …
599644
  • 561
  • 2
  • 15
3
votes
1 answer

How to compose props across component in reason-react bindings?

I am currently writing a material-UI reason-react binding and I want to know how I can re-use previously define Props. The Select component spreads all of the Input props into itself, in the underlying react-js lib. this is done by spreading props…
user465374
  • 1,521
  • 4
  • 20
  • 39
2
votes
1 answer

How to read JSON with unknown key in ReasonML?

I am writing a simple application that display dog images from Dog API. I used bs-json to make it a record and use it later. The list of breeds can be obtained by the API. The response looks like this. { "message": { "breed": ["array of…
2
votes
1 answer

How would I write a generic function to handle multiple record types in ReScript?

Given the following contrived example, is it possible to write a get function that can handle any record with an a property? type type_one = {a: int} type type_two = {a: int, b: int} let example_one = {a: 1} let example_two = {a: 1, b: 2} let get…
nickbreaton
  • 65
  • 1
  • 7
2
votes
1 answer

Infinite Lists / Streams in ReScript

I can't seem to find the correct typing for an infinite list in ReScript. I first tried: type rec stream<'a> = ('a, () => ('a, stream<'a>)) Which was incorrect because ReScript thought the type was cyclic. So instead I tried: type rec stream<'a> =…
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46
2
votes
3 answers

How do you call an uncurried function with unit in ReScript/ReasonML?

Say that I have an uncurried function like: let echo(. a) = a; I can call this funcition fine with most literals like: echo(. 1) echo(. "Hello") but when I am trying to call it with void, I get an error: echo(. ()) //This function has arity1 but…
namesis
  • 157
  • 10
2
votes
1 answer

Converting from Js.Promise to `reason-promise` in ReasonML

I have a situation where a library is using reason-promise as a default one branch and not another. I am finding it difficult to switch from one branch to another because I can't, for the life of me, figure out how to use reason-promise. I am not…
armand
  • 693
  • 9
  • 29
2
votes
1 answer

how can I alphabetically sort an array of records where a record has a name: string field?

let items = [| {name: "b"}, {name: "c"}, {name: "a"}|]; // expected output [| {name: "a"}, {name: "b"}, {name: "c"}|]; Was thinking about using Belt.SortArray.stableSortBy but requires an int.
cuadraman
  • 14,964
  • 7
  • 27
  • 32
2
votes
1 answer

How do I package a node module for BuckleScript / ReasonML?

Background I'm an absolute beginner in BuckleScript, and while I've downloaded packgages with npm before, I've never written a library. Goal: installing my new package local package in my project using npm I am trying to wrap some parts of the…
Eleanor Holley
  • 691
  • 1
  • 7
  • 27
1 2
3
12 13