Description #
ReasonML (or Reason) is a syntax layer and toolchain on top of OCaml that offers JavaScript developers a familiar, modern, and expressive syntax for writing strongly typed, functional code. It compiles to efficient native or JavaScript output via BuckleScript or ReScript.
History #
ReasonML was created by Jordan Walke, the developer behind React, and released by Facebook in 2016. Its goal was to make OCaml more accessible to JavaScript developers while maintaining its functional and type-safe nature. It has since evolved into ReScript, though Reason syntax is still supported in many projects.
Hello World Code #
print_endline("Hello, World!");
How to Run #
Option 1: Online
Option 2: Local
- Install Reason and BuckleScript:
npm install -g bs-platform
Compile and run:
bsc hello.re
Key Concepts #
- Strong static typing
- Algebraic data types
- Pattern matching
- Immutable data by default
- Functional-first, imperative-friendly
- Interoperable with OCaml and JavaScript
- JavaScript compilation via BuckleScript/ReScript
- Type inference
- Modern syntax with type safety
- Compile-to-JS and native targets
Try It Online #
Fun Facts #
- Created by the inventor of React to bridge functional OCaml with JS.
- ReScript is its modern successor focused solely on JS compilation.
- Type-safe bindings allow using Reason to write entire frontends with React.