Questions tagged [reason]

Reason is a syntax and toolchain powered by OCaml. Use with [tag:ocaml] for questions relating to the semantics of the language, and with [tag:bucklescript] for questions relating to the JavaScript workflow.

Reason is a new syntax and toolchain powered by . It gives OCaml a familiar syntax geared toward JavaScript programmers, and caters to the existing / workflow folks already know.

Reason is tightly associated and usually used in conjunction with to target JavaScript, but can also compile to native code using the standard OCaml compiler.

Reason is an open source community project initiated and led by Facebook.

Useful resources

Related tags

360 questions
5
votes
1 answer

Where is Reason's cons (::) operator?

The cons (::) operator is a fundamental part of 1) writing recursive list functions in OCaml and similar languages, and 2) pattern matching on lists. However, I can't find anything in Reason's documentation concerning cons, and in the REPL, this…
jayelm
  • 7,236
  • 5
  • 43
  • 61
4
votes
1 answer

ReScript, TypeScript: Cannot find module '@rescript/react/src/ReactDOM.gen' or its corresponding type declarations

I am gradually rewriting an application with React to TypeScript into ReScript. I've already implemented few components in ReScript, but this is the first one, where I use ReactDOM.Style.t as property to my component. Here is my minimized component…
Sergey Potapov
  • 3,819
  • 3
  • 27
  • 46
4
votes
4 answers

How to create an efficient group by function without mutation?

Is there a way to efficiently implement a group by function without mutation? Naive implementation: ReScript playground JavaScript (see below) var messages = [ {insertedAt: "2021-01-10"}, {insertedAt: "2021-01-12"}, {insertedAt:…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
4
votes
1 answer

useEffect vs useEffect0 in ReasonML

I am trying understand what the difference is between: React.useEffect(() => { let timerId = Js.Global.setInterval(() => tick(), 1000); Some(() => Js.Global.clearInterval(timerId)); }); React.useEffect0(() => { let timerId =…
armand
  • 693
  • 9
  • 29
4
votes
1 answer

How to conditionally render reason-react component?

Something that has started appearing in my code quite a bit is: {if (condition) { ; } else {
; }} ; Basically I only want the Child to render if the condition is true, otherwise…
JasoonS
  • 1,432
  • 3
  • 13
  • 26
4
votes
1 answer

ReasonML Type mismatch with same type

I'm receiving a type mismatch even though I'm using the same type in ReasonML. The error is: [1] We've found a bug for you! [1] /Users/gt/work/real-and-open/frontend/src/domain/classroom/views/RosterLayoutHeader.re 42:10-70 [1] [1] 40 ┆…
GTDev
  • 5,488
  • 9
  • 49
  • 84
4
votes
1 answer

How should I point to a record field in case of extensible object types?

Thinking of a way to define a simple lens on an object in Reason. I try to use extensible objects (with .. prepended to field list) with the following code: type hasName('a, 't) = {.. name: 't} as 'a; type lens('s, 'v) = { get: 's => 'v, set:…
user954298
  • 41
  • 1
  • 3
4
votes
1 answer

Using bs-json to Decode object with dynamic keys in root

I am trying to decode the following JSON object into a Reason object. {"AAPL":{"price":217.36}} The key in the root of the object is dynamic. The following general example works when the key is not in the root. How would I change it so it works for…
Sepehr Sobhani
  • 862
  • 3
  • 12
  • 29
4
votes
1 answer

ReasonML performance against imperative vanilla JavaScript

Disclaimer: I am ReasonML beginner. I have started playing with ReasonML lately and I have noticed a big difference in performance in contrast to vanilla JavaScript. Here's my examples against a simple puzzle solving function (puzzle taken from:…
skay-
  • 1,546
  • 3
  • 16
  • 26
4
votes
2 answers

Deploying a ReasonML function to Google Cloud Functions

I am trying to write a deployment process for taking a ReasonML .bs.js output and deploying it as a Google Cloud function. Here is the ReasonML code: /*! * My first ReasonML Google cloud function. * Hadil G. Sabbagh */ open Express; let…
4
votes
1 answer

Circular dependency reasonml

Let's say that I have a 1 -> n relation: one todo can has many (or zero) notes and a note can have zero or one todo. How can I achieve this relation in ReasonML? (binding for an external lib) Here is what I have come with at the moment (which is of…
Quang Linh Le
  • 751
  • 1
  • 7
  • 16
4
votes
2 answers

Combine multiple variants into one variant

Is there a way to combine multiple variants together into one? Something like this: type pet = Cat | Dog; type wild_animal = Deer | Lion; type animal = pet | wild_animal; This is a syntax error, but I would like animal to become a variant with four…
Robz
  • 1,747
  • 5
  • 21
  • 35
4
votes
2 answers

Unable to destructure Functor(Module)

This syntax would be very useful—is there a reason for this not working? Thanks! module Foo = { let bar: string = "bar" }; let bar = Foo.bar; /* works */ let { bar } = Foo; /* Unbound record field bar */ Try it online!
M. Walker
  • 603
  • 4
  • 14
4
votes
1 answer

Is it possible to not export a module in BuckleScript?

Is it possible to not export certain internal modules that should not be used directly by package consumers?
norvana
  • 45
  • 3
4
votes
3 answers

Does ReasonML support async/await?

I have been going through the JS -> Reason cheatsheet on the Reason ML website. They are very helpful, but none cover the async/await syntax available in modern ES. What is the Reason ML equivalent of this? import fs from 'mz/fs'; // A cat-like…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
1 2
3
23 24