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
0
votes
1 answer

Unused Variable Warning in ReasonML

When I use Invalid_argument() variant exception in a switch case, it expects a string argument. let subStr = try(String.sub(input^, index, 1)) { | Invalid_argument(err) => "" }; but if I don't use the err variable, it shows an unused variable…
Tahnik Mustasin
  • 2,216
  • 2
  • 18
  • 21
0
votes
2 answers

`self.send` on ReasonReact Compile-time Error

Given the following: $cat src/Greeting.re let component = ReasonReact.reducerComponent("Greeting"); type action = | Click; type state = { count: int }; let make = (_children) => { ...component, initialState: () => {count: 0}, reducer:…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
2 answers

reason-ml is this a type inference issue?

I'm currently trying Reason and facing an error I don't understand This is my code: let mult = (x:float, y:float):float => x * y; When I compile it with BuckleScript I get the following error: We've found a bug for you! …
netlyonel
  • 155
  • 1
  • 2
  • 8
0
votes
1 answer

Focusing an input field in a React component – getting type error trying to create a ref

I have a React component that contains a text element. When the component is mounted, I want the text cursor to be set in the input field, i.e. I want the text input element to have the focus. In a “traditional” JavaScript React component, I…
Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
0
votes
1 answer

How to define type for props

Code: let component = ReasonReact.statelessComponent("Page"); type matchParams = {. id: int }; type match = {. params: matchParams }; type userProps = {. match: match }; let home = ; let user = (~props:userProps) =>
kirsanv43
  • 358
  • 2
  • 13
0
votes
0 answers

ReasonML on VSCode - "Go to Definition" from inside *.ml library file doesn't work

I'm trying out ReasonML on VSCode. But have a little problem with "Go to Definition" feature. From a SomeFile.re I can right click -> "Go to Definition" on a standard library function (in this case Format.printf(...)) and it will jump to the…
hendysg
  • 136
  • 1
  • 5
0
votes
1 answer

Spread syntax in function call in Reason

In Javascript you can use the spread syntax in a function call like this: console.log(...[1,2,3]); Is there an equivalent in Reason? I tried the following: let bound = (number, lower, upper) => { max(lower, min(upper, number)); }; let parameters…
Kasper
  • 12,594
  • 12
  • 41
  • 63
0
votes
1 answer

ReasonML Quick Start failing to compile

After following the instruction on the quick start page of ReasonML, the command npm run start fails to compile the application. It shows that the code has a syntax error.
Tahnik Mustasin
  • 2,216
  • 2
  • 18
  • 21
0
votes
1 answer

How to create an optional module signature type in OCaml/Reason

I am trying to follow the builder design pattern using modules in Reason. I have the following type: type userBuilderType = { mutable name: string, }; As well as signature type: module type UserBuilderType = { let name: string; }; I am…
Charlie-Greenman
  • 1,469
  • 1
  • 16
  • 36
0
votes
1 answer

Making ReasonML/Bucklescript output ES5 compatible code

While using ReasonML and Bucklescript, is it possible to configure Bucklescript so it won't generate export statements? I'd prefer if the generated code could be used as is in a browser, that is, being ES5 (or ES6) compatible. Edit: OK, while trying…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
0
votes
1 answer

Two ways to define a function

Why are there two ways to define a function in reason, and how exactly are they different (both compile to identical JavaScript) let f1 = fun (a) => 123; let f2 a => 123; try this snippet
dark_ruby
  • 7,646
  • 7
  • 32
  • 57
0
votes
1 answer

OOP - How to create an instance of one type called to another type in Reason

I have two abstract products types: type abstractProductA = {. methodA: string }; type abstractProductB = {. methodB: int }; Used to create the following product classes: class productA1 = { pub methodA => "This is methodA of…
Charlie-Greenman
  • 1,469
  • 1
  • 16
  • 36
0
votes
1 answer

reducerComponent can't be found in ReasonReact

I'm trying to follow this Reason React tutorial to build a simple TodoApp: However when changing the type of the component from statelessComponent to reducerComponent I get the following error: We've found a bug for…
Harald Gliebe
  • 7,236
  • 3
  • 33
  • 38
0
votes
2 answers

Limit recursion to the first three elements of list of floats

I'm new to functional programming (ReasonML / OCaml). I have a list of floats. I want to get the first three non-zero items of a list and no more. Items can be positive, negative, and zero. How can recursion be limited until the first three…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
0
votes
2 answers

Why would it matter where a type declaration is located?

The documentation for ReasonReact specifies where in the code a type should be declared: The state type could be anything! An int, a string, a ref or the common record type, which you should declare right before the reducerComponent call: type…
ændrük
  • 782
  • 1
  • 8
  • 22
1 2 3
23
24