$30 off During Our Annual Pro Sale. View Details »

What is ReasonML?

What is ReasonML?

Axel Rauschmayer

February 01, 2018
Tweet

More Decks by Axel Rauschmayer

Other Decks in Programming

Transcript

  1. What is ReasonML?
    Munich, 2018-02-01

    View Slide

  2. ReasonML
    • A new programming language by Facebook.
    • Supports several styles:
    • Functional programming
    • Imperative programming
    • Object-oriented programming
    In a nutshell: different syntax for OCaml

    View Slide

  3. OCaml syntax
    (.ml, .mli)
    ReasonML syntax
    (.re, .rei)
    OCaml AST
    Bytecode Native code JavaScript
    BuckleScript
    ocamlopt
    ocamlc
    ReasonML inside the OCaml ecosystem

    View Slide

  4. type tree = Leaf | Node(int, tree, tree);
    let rec sum = (x) =>
    switch (x) {
    | Leaf => 0
    | Node(value, left, right) =>
    value + sum(left) + sum(right);
    };
    let myTree =
    Node(
    1,
    Node(2, Node(4, Leaf, Leaf),
    Node(6, Leaf, Leaf)),
    Node(3, Node(5, Leaf, Leaf),
    Node(7, Leaf, Leaf))
    );
    sum(myTree) |> print_int;
    • Syntax: JS
    • Style: FP
    • No type annotations

    (x, myTree)

    View Slide

  5. Dr. Axel Rauschmayer, @rauschma
    Foundation: OCaml
    • Proven in the real world
    • Created in 1996 at INRIA (France)
    • Used at Facebook, Bloomberg, Jane Street, etc.
    • An object-functional language.
    • Supports mutable state (as an “escape hatch”).
    • Compiles to bytecode, native code, good-looking JavaScript
    • Building JavaScript is fast
    5

    View Slide

  6. Dr. Axel Rauschmayer, @rauschma
    Focus of ReasonML
    • Tooling (IDE support etc.)
    • Interoperability with JavaScript
    • React (built-in syntax etc.)
    • Better standard library
    6

    View Slide

  7. Dr. Axel Rauschmayer, @rauschma
    Future
    Current weaknesses:
    • Better support for JS Promises
    • Better standard library (currently not always cross-platform)
    • Better support for Unicode (currently not cross-platform)
    • Better support for overloading (ad-hoc polymorphism)
    • No more + vs. +.
    • Similar to Haskell’s type classes
    • Truly native React Native
    • Long term: multicore
    7

    View Slide

  8. Dr. Axel Rauschmayer, @rauschma
    ReasonReact
    • Batteries included:
    • Router
    • Redux
    • Typed support for GraphQL via graphql_ppx
    8

    View Slide

  9. Dr. Axel Rauschmayer, @rauschma
    Tips for getting started
    • Try out quickly:
    • Interactive command line (offline): rtop
    • Online playground
    • Write sync Node.js-based shell scripts
    • Generate template projects. E.g.:

    bsb -init my-first-app -theme basic-reason
    • Visual Studio Code
    9

    View Slide

  10. Dr. Axel Rauschmayer, @rauschma
    Documentation
    • Online docs. Well-written!
    • Material on OCaml
    • Convert OCaml ↔ ReasonML: refmt,
    playground
    • 2ality.com/2017/11/about-reasonml.html
    10

    View Slide