Web Development with ReasonML

Book description

ReasonML is a new, type-safe, functional language that compiles to efficient, readable JavaScript. ReasonML interoperates with existing JavaScript libraries and works especially well with React, one of the most popular front-end frameworks. Learn how to take advantage of the power of a functional language while keeping the flexibility of the whole JavaScript ecosystem. Move beyond theory and get things done faster and more reliably with ReasonML today.

ReasonML is a new syntax for OCaml, a battle-tested programming language used in industry for over 20 years. Designed to be familiar to JavaScript programmers, ReasonML code compiles to highly readable JavaScript. With ReasonML, you get OCaml's powerful functional programming features: a strong static type system with an excellent type inference engine, pattern matching, and features for functional programming with immutable variables. ReasonML also allows flexibility with opt-in side effects, mutation, and object-oriented programming. ReasonML hits the sweet spot between the pure theoretical world and the laissez-faire approach of JavaScript.

Start using ReasonML's powerful type system as you learn the essentials of the language: variables and arithmetic operations. Gain expressive power as you write functions with named parameters and currying. Define your own data types, and integrate all these capabilities into a simple web page. Take advantage of ReasonML's functional data structures with map and reduce functions. Discover new ways to write algorithms with ReasonML's recursion support. Interoperate with existing JavaScript libraries with bindings, and write reactive web applications using ReasonML in tandem with React. Reinforce concepts with examples that range from short, tightly focused functions to complete programs, and practice your new skills with exercises in each chapter.With ReasonML, harness the awesome power of a functional language while retaining the best features of JavaScript to produce concise, fast, type-safe programs.

What You Need:

You'll need to have node.js (version 10.0 or above) and npm (version 5.6 or above). Once you install the bs-platform package and fire up a text editor, you're ready to go. (There are plugins for many popular editors that will make editing easier.)

Publisher resources

View/Submit Errata

Table of contents

  1.  Introduction
    1. What Makes ReasonML Special?
    2. What Should You Know?
    3. What’s in This Book?
    4. Acknowledgments
    5. Online Resources
  2. 1. Make Your First ReasonML Project
    1. Running Your First Program
    2. Using Variables and Doing Arithmetic in ReasonML
    3. Working with Types
    4. Doing Conditional Computation
    5. Working with Strings
    6. It’s Your Turn
    7. Summing Up
  3. 2. Writing Functions
    1. Defining Functions
    2. Using Labeled Parameters
    3. Providing Default Values for Labeled Parameters
    4. Shortening Code with bsrefmt
    5. Specifying Parameter Types
    6. Writing Functions without Parameters or Return Values
    7. Currying: Handling One Argument at a Time
    8. Currying and Labeled Parameters
    9. It’s Your Turn
    10. Summing Up
  4. 3. Creating Your Own Data Types
    1. Renaming a Data Type
    2. Creating Variant Data Types
    3. Using Variant Data Types
    4. Creating Variant Data Types with Parameters
    5. It’s Your Turn
    6. Using the option Type
    7. Working with option Values
    8. Working with Belt.Option
    9. Using Pipe First
    10. It’s Your Turn
    11. Getting Another Perspective
    12. Summing Up
  5. 4. Interacting with Web Pages
    1. Creating an Example Web Page
    2. Setting Up the Project
    3. Accessing the DOM
    4. Building the Web Bundle
    5. Completing the Calculation
    6. Getting a Value
    7. It’s Your Turn
    8. Reviewing DOM Functions
    9. Summing Up
  6. 5. Using Collections
    1. Accessing Functions in Other Files
    2. Grouping Heterogeneous Data with Tuples
    3. Using Lists
    4. Manipulating Lists with Belt.List
    5. Using map, keep, and reduce with Lists
    6. Interlude: Displaying Lists
    7. Using Arrays
    8. Using map, keep, and reduce with Arrays
    9. Putting Arrays to Work
    10. It’s Your Turn
    11. Summing Up
  7. 6. Repeating with Recursion
    1. Defining Recursion
    2. Analyzing a Recursive Algorithm
    3. Writing Recursive Functions
    4. Interlude: Measuring Performance
    5. Understanding Tail Recursion
    6. Practicing More Recursion
    7. Using Recursion with Lists
    8. It’s Your Turn
    9. Summing Up
  8. 7. Structuring Data with Records and Modules
    1. Specifying Records
    2. Accessing and Updating Records
    3. Creating Modules
    4. Creating Interface Files for Modules
    5. Putting Modules to Work
    6. It’s Your Turn
    7. Summing Up
  9. 8. Connecting to JavaScript
    1. Adding Raw JavaScript
    2. Binding to Existing Functions
    3. Interoperating with Data Types
    4. Interoperating with Objects
    5. It’s Your Turn
    6. Working with JSON
    7. Setting Up the Server
    8. Implementing the Client
    9. It’s Your Turn
    10. Summing Up
  10. 9. Making Applications with Reason/React
    1. Viewing React from 20,000 Meters
    2. Starting a ReasonReact Project
    3. Investigating the Sample Project
    4. Creating a More Complex Stateless Component
    5. It’s Your Turn
    6. Using Stateful Components
    7. Putting Components Together
    8. It’s Your Turn
    9. Adding Side Effects with Storage
    10. It’s Your Turn
    11. Summing Up
  11. A1. Understanding the ReasonML Ecosystem
    1. In the Beginning was OCaml
    2. Enter ReasonML
    3. A Non-Unified Ecosystem
    4. Summing Up
  12. A2. Miscellaneous Topics
    1. Switching to fun
    2. Using open
    3. Using Belt.Map.update
    4. Dangerous Interop
    5. Hiding Type Information

Product information

  • Title: Web Development with ReasonML
  • Author(s): J. David Eisenberg
  • Release date: March 2019
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680506891