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

How to define a binding that accepts multiple types in the function signature using reason-react?

When defining a reason-react binding and I want to know how I can determine a binding that accepts multiple types. For example, I have an argument ~value that should accept: string, number, array(string) or array(number). At the moment I am using…
user465374
  • 1,521
  • 4
  • 20
  • 39
4
votes
1 answer

How to create internal value in a module using OCaml/Reason

I have the following module: type userBuilderType = { mutable name: string, }; module BuilderPattern = { let builder () => { name: "", }; let setName = fun name => builder.name = name; let getName =…
Charlie-Greenman
  • 1,469
  • 1
  • 16
  • 36
4
votes
1 answer

How to extend JS class in ReasonML

For example, I have an es6-like class: class Foo {...} And I want to extend it: class Bar extends Foo {...} In reason-react documentation I found examples, but I'm not sure that it's appropriate for me: let component = ReasonReact.reducerComponent…
S. Zobov
  • 154
  • 2
  • 15
4
votes
1 answer

Reasonml type with multiple arguments, Error exception Failure("nth")

I have got Error while compiling the following code type shape = | Circle int | Square int | Rectangle int int; let myShape = Circle 10; let area = switch myShape { | Circle r => float_of_int (r * r) *. 3.14 | Square w => float_of_int…
kkpoon
  • 1,939
  • 13
  • 23
4
votes
3 answers

Call graph generator for OCaml or Reason

I want to analyze a OCaml/Reason code repository and understand calls between various functions. Is there a tool that provides such functionality?
xennygrimmato
  • 2,646
  • 7
  • 25
  • 47
3
votes
1 answer

How do I implement hash functions for arbitrary record types in ReScript?

I'm exploring ReScript for the first time. I want to build a hashmap using a record type as my key type, and I'm looking for guidance on implementing the hash function. Here's my ReScript code: type pointer = { id: string, table: string, spaceId:…
Just Jake
  • 4,698
  • 4
  • 28
  • 33
3
votes
1 answer

How to write custom ppx decorator to rescript?

I need to generate a value with a different type from my passed type. This is the first time I write on ocaml-like, and for example, in a familiar me haskell I would use Data.Generics. How I have understood I need to use decorator and ppx. I wrote…
Gleb Patcia
  • 365
  • 2
  • 15
3
votes
1 answer

How do I compare values for equality by Type Constructor?

Background I'm a relative newcomer to Reason, and have been pleasantly suprised by how easy it is to compare variants that take parameters: type t = Header | Int(int) | String(string) | Ints(list(int)) | Strings(list(string)) | Footer; Comparing…
3
votes
1 answer

How to extend HTML attribute interfaces when designing reasonml react components?

I'm learning reasonml and quite excited about it. Something I often do in typescript react code is: type Props = React.HTMLProps & { foo: boolean } const SuperButton: React.FC = (props) =>
3
votes
1 answer

Can I implement multiple module types with 1 module?

Given these module types: module type CodecTypes = { type t; type token; }; module type Decode = { include CodecTypes; let decode: BsGenericParser.Parse.parser(token, t); }; module type Encode = { include CodecTypes; let encode: t =>…
Felix
  • 8,385
  • 10
  • 40
  • 59
3
votes
1 answer

How can I destructure a tuple into a List.map in ReasonML?

let numbers = [1, 5, 6, 12, 52, 25]; let state: list((int, bool)) = numbers |> List.map(n => (n, false)); state |>…
sheki
  • 8,991
  • 13
  • 50
  • 69
3
votes
3 answers

How to Use SVG with React and ReasonML?

With create-react-app and JavaScript/TypeScript, I understand I'm able to "import" an SVG as noted below. How may I do so with ReasonML? import { ReactComponent as Logo } from './logo.svg'; function App() { return (
{/* Logo is an…
Ari
  • 4,121
  • 8
  • 40
  • 56
3
votes
1 answer

How to convert JSON schema into the OCaml/ReasonML type

There is a JSON file, it has been converted to JSON-schema and the schema definition in ReasonML type. Please help to comment the following issues. Is it a good choose to use JSON schema as a table/schema definition? It seems it is a de-facto…
madeinQuant
  • 1,721
  • 1
  • 18
  • 29
3
votes
1 answer

why does wrapping functions in iife cause weak types?

I'm trying to figure out a way to hide certain helper functions and related stuff from the user of a module and thought using an IIFE would work, yet it fails because a type variable cannot be generalized? I think I've boiled it down to the most…
hesxenon
  • 501
  • 3
  • 12
3
votes
1 answer

How to create Map of tuples in ReasonML?

I'm very new to Reason. I have a tuple containing two strings and want to make a Map where the keys are of that tuple type. How should I go about doing it?
Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141