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

graphql reason-apollo - recursive parsing of options

I'm using Reason-Apollo to parse a pretty nested GraphQL response from my server. I'm having trouble parsing the hairy tree of options returned from my GraphQL server (I'm using django-graphene). Here is the GraphQL query and the Reason React…
Myer
  • 3,670
  • 2
  • 39
  • 51
5
votes
1 answer

How to bind to and use a higher-order component in ReasonReact

Let's say I have a higher-order component, something like the following trivial definition, exported from the JavaScript module ./hoc.js: export const withStrong = Component => props => Assuming I have…
glennsl
  • 28,186
  • 12
  • 57
  • 75
5
votes
2 answers

Reason React and Graphql handling ENUM values

Just started to learn reason react and struggle with a graphql setup trying to read an ENUM value. setup reason react apollo graphql graphql_ppx github graphql endpoint i am fetching the latest pull request data over the github api and reading the…
roman
  • 889
  • 9
  • 16
5
votes
5 answers

How do you take a slice of a list in OCaml/ReasonML?

For example in Ruby you could do something like: list = ["foo", "bar", "baz", "qux", "quux", "corge"] result = list[2..4] And result would contain ["baz", "qux", "quux"]. How would you do this in OCaml/ReasonML?
Erik
  • 4,268
  • 5
  • 33
  • 49
5
votes
1 answer

How to write reasonml binding for a union type

I am trying to write bindings for https://github.com/oblador/react-native-keychain/blob/master/typings/react-native-keychain.d.ts#L76 getGenericPassword returns false if an error, else an object (credentials). I am not sure this union type can be…
bsr
  • 57,282
  • 86
  • 216
  • 316
5
votes
2 answers

How to handle global DOM events in ReasonML/ReasonReact?

What's the most idiomatic way of listening/handling global DOM events in ReasonML. I'm building a ReasonReact version of the 2048 game where I need to listen for keyboard events. In a standard JS/React app I'd have a component with a…
Alan R. Soares
  • 1,735
  • 1
  • 15
  • 19
5
votes
2 answers

When to use piping |> versus arguments

In Reason (and OCaml), there is a non-traditional way of passing arguments using the |> operator. What is the convention for when it should be used? I am currently using it all over the place just because of how novel I find it.
Slava Knyazev
  • 5,377
  • 1
  • 22
  • 43
5
votes
1 answer

Shebang support in reasonML

I'm trying to write a command line tool in reasonML. So I inserted a shebang(#! /usr/bin/env node) at the first line, but the compiler failed to compile it. How do I add a shebang to the compiled output?
Jian
  • 3,118
  • 2
  • 22
  • 36
5
votes
1 answer

Error while compiling reducerComponent "Is this a ReasonReact reducerComponent or component with retained props?"

I'm getting an error when creating a reducerComponent: Code type state = {repoData: RepoData.repo}; let dummyRepo: RepoData.repo = { stargazers_count: 27, full_name: "jsdf/reason-react-hacker-news", html_url:…
Ashley Coolman
  • 11,095
  • 5
  • 59
  • 81
5
votes
2 answers

How to add custom method to ReasonReact component?

I am very new to ReasonML. I am able to successfully create a stateless component with ReasonReact, but I have not figured out how I might add a custom method to the component (e.g. Next.js' static getInitialProps). When attempting to define the…
David
  • 1,330
  • 17
  • 31
5
votes
1 answer

Displaying type and value with Reason

The OCaml REPL displays the value and type of any expression. For instance, evaluating: let rec map f = function | [] -> [] | x::l -> f x :: map f l;; Gives: val map : ('a -> 'b) -> 'a list -> 'b list = This is unvaluable for…
Aristide
  • 3,606
  • 2
  • 30
  • 50
5
votes
1 answer

Unbound record field id error

I am trying out Reason-React. I am facing a problem when I try to add a key to one of the components. I have a TodoApp that takes a list of TodoItem as state. The app works fine when I don't have a key for the TodoItem. When I add it, however I am…
leoOrion
  • 1,833
  • 2
  • 26
  • 52
5
votes
1 answer

Compiling Reason source files to the same directory as the source files

I'm writing a node application, where I would like to mix Reason and raw JavaScript. This section in the bucklescript documentation describes it When user has an existing JS project, it makes sense to output the JS file in the same directory as…
Pete
  • 12,206
  • 8
  • 54
  • 70
5
votes
1 answer

Reason module system

https://facebook.github.io/reason/modules.html#modules-basic-modules I don’t see any import or require in my file; how does module resolution work? Reason/OCaml doesn’t require you to write any import; modules being referred to in the file are…
tuchk4
  • 2,270
  • 5
  • 21
  • 34
5
votes
1 answer

How can I parse this JSON to a record type?

I have some data I'll be fetching at runtime: /* {id: 1, name: 'brad', age: 27, address: { city: 'city1', state: 'state1' } } */ let data = "{\"id\":1,\"name\":\"brad\",\"age\":27,\"address\":{\"city\":\"city1\",\"state\":\"state1\"}}"; Using…
Bradford
  • 4,143
  • 2
  • 34
  • 44
1
2
3
23 24