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

How can I define a new type and a type for list of this type in ocaml?

I'm new to ocaml and have defined a type. type options = | Rock | Paper | Scissors I want to also define a list of options. This is how I'm attempting it type opts = list options; Merlin gives me this error when I try and pass a literal list…
ceckenrode
  • 4,543
  • 7
  • 28
  • 48
0
votes
1 answer

How to bind a whole module as a function?

I'm playing with reason, and I wanted to try to do the FFI for debug in order to learn. I have this code module Instance = { type t; external t : t = "" [@@bs.module]; }; module Debug = { type t; external createDebug : string => Instance.t…
ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
0
votes
1 answer

How to use switch operator and best way to iterate string and detect symbols

How to implement this logic with switch operator instead of large if/else? type token = | DOT | OPEN_BRACKET | SYMBOL; let dot_code = ".".[0] |> Char.code; let open_bracket_code = "{".[0] |> Char.code; let char_to_token symbol :token =>…
tuchk4
  • 2,270
  • 5
  • 21
  • 34
0
votes
1 answer

OCaml dynamic function name

I have a list of tags: let tags = ["div", "h1", "p"] Can I generate a module which contains functions with those tags as names? /* don't mind the syntax, it's Facebook's Reason (new interface to ocaml) */ let module DOM = { let div props…
Seneca
  • 2,392
  • 2
  • 18
  • 33
-1
votes
1 answer

How can I convert JavaScript values to a variant in reasonml?

There are three values in JavaScript: Result.granted Result.denied Result.neverAskAgain How can they be converted to a variant? type result = | Granted | Denied | NeverAskAgain;
-1
votes
1 answer

How can we alias props when using the Hooks API?

Previously, I was using [@bs.as "in"] like so. [@bs.deriving abstract] type cssTransitionProps = { [@bs.as "in"] _in: bool, timeout: int, classNames: string, }; How can I do something similar here? module CSSTransition = { [@bs.module…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
-1
votes
2 answers

How do I pass Variants as props to React Components in ReasonML?

I have tried the following approach to be able to send variants as props. type ipAddr = | IPV4 | IPV8; [@react.component] let make = () => { let appData = Data.tileData;
Deadfish
  • 2,047
  • 16
  • 17
-1
votes
1 answer

Managing a form with a lot of fields

I'm writing a form in ReasonReact. I used reducerComponent and a record as state. Let's say I have something like this: type state = { field1: string, field2: int, }; type action = | SetField1(string) | SetField2(int); let component =…
user3139560
  • 19
  • 1
  • 3
-1
votes
1 answer

What does this syntax mean (...)

I'm putting my hands into reason-react. In the following code : let component = ReasonReact.statelessComponent("Component3"); let make = (~name, _children) => { ...component, render: self => , }; I don't understand…
espern
  • 659
  • 6
  • 14
-1
votes
1 answer

Type error when processing graphql result

I just started playing with reasonML and graphql and have built a simple react component that retrieves data from a world cup API. My code is below: [@bs.module] external gql: ReasonApolloTypes.gql = "graphql-tag"; module GetMatches = [%graphql …
jwesonga
  • 4,249
  • 16
  • 56
  • 83
-1
votes
2 answers

bucklescript method definition = string

Pretty much all bucklescript examples have something that has a syntax like this: [@bs.send.pipe : t('options)] external parse : array(string) => 'options = "parse"; or like this: [@bs.module "express"] external make : (string, options) => t =…
Abraham P
  • 15,029
  • 13
  • 58
  • 126
-1
votes
1 answer

Pass arguments to rendered element from HTML

I have a component that I render on HTML based on class, with the function renderToElementWithClassName. I know I can pass values to component in the function (renderToElementWithClassName(, "class");. However, I need to be able…
Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43
-2
votes
1 answer

Why is ReasonML throwing this type error?

I'm trying to create an iterative function that takes in an 'a => 'a function, and a natural number which indicates how many times to iterate this function. It will output another 'a => 'a function. Example input: let func: int => int = num =>…
-2
votes
1 answer

This procedure (elementSeparator) is giving a type error in ReasonML

This code: let initialRows = 5; let initialCols = 7; /* Player 1 is P1, Player 2 is P2 */ type whichPlayer = | P1 | P2; /* Either Player 1 or Player 2 has won the game, it is a draw, or it is ongoing…
-6
votes
1 answer

How might I find the number of occurrences of elements in a list in ReasonML?

How might I find the number of occurrences of elements in a list in ReasonML? I'm not exactly sure how to attempt this. Thank you!
1 2 3
23
24