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
2 answers

Decoding Json/Reading Errors in ReasonML

I have got an graphql query coming back from aws's appsync service. This is the json that comes back from the query. https://github.com/idkjs/reason-apollo-question/blob/600584c454ffb2efd08b8e42e3adca0eb151ba60/scratch/persons.json#L1-L27 { …
armand
  • 693
  • 9
  • 29
0
votes
1 answer

Create binding based on external JS

In this post, the autor teaches how to make a binding from a NodeJS library to Reason. However, I want to create a binding for Google Maps Javascript API, which can't be installed through NPM. Rather, it's usually loaded in the bottom of with…
Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43
0
votes
2 answers

How to pass query string parameters with bs-fetch?

What is the proper way to pass query string parameters to bs-fetch? Currently, I have: Fetch.fetch("https://example.com/api?param1=value1¶m2=value2") Obviously, this is not sustainable for larger parameter lists. Is there a better way to do…
csb
  • 674
  • 5
  • 13
0
votes
1 answer

Exception patterns must be at the top level of a match case

This compiles: let inputFile = open_in("test.txt"); let line = try(input_line(inputFile)) { | End_of_file => "end of file" }; print_endline(line); But not this: let inputFile = open_in("test.txt"); try(input_line(inputFile)) { | line =>…
Robz
  • 1,747
  • 5
  • 21
  • 35
0
votes
2 answers

Is there a way to get the tag of a polymorphic variant as a variable in ReasonML

I'm looking to see if i can genericize the following code a bit. type recordType = [ | `Todo(todo, idFunction) | `TodoItem(todoItem, idFunction) let commitItemToSchema = (normalizedSchema, recordType) => { switch(recordType){ | `Todo …
GTDev
  • 5,488
  • 9
  • 49
  • 84
0
votes
1 answer

Normalizr for ReasonML

I know ReasonML is a new language so tooling will be a bit behind. But I was wondering if there was a Bucklescript or ReasonML tool that acts as a Normalizr for data for reason-react. I know I can just make bindings and put them into Normalizr…
GTDev
  • 5,488
  • 9
  • 49
  • 84
0
votes
1 answer

ReasonReact unsafe string to element

I made a function that takes an string and replace a specific substring within it: let mark = (str: string, sub: string) : string => { let re = Js.Re.fromString("(" ++ sub ++ ")"); Js.String.replaceByRe(re, "$1", str); }; It…
Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43
0
votes
1 answer

ReasonML equivalent of OCaml ExtString.exists

ReasonML is built upon OCaml, and much of OCaml stdlib is available on ReasonML. However, ExtString is not one of them. I'm in need of using ExtString.exists to verify if a substring sub exists within a string str. I know that I can make my own…
Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43
0
votes
1 answer

How to solve in ReasonReact - "This has type: (ReasonReact.reactElement, string) => unit But somewhere wanted: at actElement

I have a very compact ReasonReact reducer component, which has a component, initialState, reducer, action, and render function as follows: type actions = | DoNothing; let component = ReasonReact.reducerComponent("ShowHide"); let make = (~name,…
Charlie-Greenman
  • 1,469
  • 1
  • 16
  • 36
0
votes
1 answer

ReasonReact.Router implementation and serving static files with Express server

I have implemented routing using the Routing feature provided in ReasonReact. It looks like this. It works great, until I have it being served by a node.js express server. It will still route, but when I refresh I get for example cannot GET /about.…
benschinn
  • 41
  • 5
0
votes
1 answer

Resolving query type with promise in bucklescript

I've got this query im trying to test with with the reason graphql_ppx library. code gist This is a screenshot of the editor type annotations: Using the @mhallin/graphql_ppx library, i've got the following query set up: module FilmQuery =…
armand
  • 693
  • 9
  • 29
0
votes
2 answers

unexpected output when pattern matching exception on a promise

I have the following piece of code: let test = Js.Promise.resolve("Hello") |> Js.Promise.then_(_obj => raise(Not_found)); let ker = switch test { | exception Not_found => Js.log("not found") | _ => Js.log("found") }; The…
Sibi
  • 47,472
  • 16
  • 95
  • 163
0
votes
1 answer

Explicitly Declaring List of Int?

How can I explicitly mark the type of let myList = [1, 2, 3]; as a list of int's? I tried let xs: 'int list = [1,2,3]; unsuccessfully through Try ReasonML.
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

Its possible use List.fold_left to returns a Js.Obj?

I'm trying to do this in ReasonML without success. The problem is that I don't know the object keys. const items = { foo: () => 'ok', bar: () => 'ok2' }; const result = Object.keys(items).reduce((acc, key) => ({ ...acc, [key]:…
norvana
  • 45
  • 3
0
votes
1 answer

Type error in render after Promise

I'm trying to render a component with reason-react after I get data from fetch but I receive a type error. This is my code: GetData.re: let get = () => Js.Promise.( Fetch.fetch("localhost:8000/data.json") |> then_(Fetch.Response.json) |>…
SHI1485
  • 121
  • 1
  • 5