Introducing ReScript: Functional Programming for Web Applications
- Length: 284 pages
- Edition: 1
- Language: English
- Publisher: Apress
- Publication Date: 2022-12-28
- ISBN-10: 1484288874
- ISBN-13: 9781484288870
- Sales Rank: #4624602 (See Top 100 Books)
This book serves as a succinct guide on ReScript, a functional language for building web applications. Using examples of ReScript language features along with explanations of fundamental concepts in functional programming, this book will show web developers with a background in JavaScript how to effectively use ReScript to its full potential.
In Introducing ReScript, you’ll learn how to use features in ReScript that JavaScript lacks, such as type inference, null-safety, algebraic data types, pattern matching, and more. Along the way, you’ll pick up functional programming concepts like immutability and higher-order functions. You’ll also gain a sense of how ReScript works under the hood and how to leverage interoperability between ReScript and JavaScript.
Whether you’re a web developer interested in dabbling with functional programming or you just want to learn how to write safer and cleaner code for web applications, this book is a great way for you to get started with ReScript.
What You Will Learn
- Use ReScript to write clean, safe, and elegant software
- Understand the features of ReScript that set it apart from JavaScript, such as type inference, null-safety, and algebraic data types
- Explore functional programming concepts like immutabhigher-orderr order functions, and pattern matching
- Use popular JavaScript libraries and frameworks in your ReScript code and integrate ReScript code into JavaScript codebases
Who This Book Is For
Web developers that want a strictly typed, safer alternative to JavaScript, as well as web developers interested in learning functional programming and leveraging the elegant and powerful functional features in ReScript.
Table of Contents About the Author About the Technical Reviewer Introduction Chapter 1: ReScript Basics Expressions, Values, and Side Effects Compile Time and Runtime Types, Typechecking, and Type Inference Primitive Types and Operators Integer and Float Boolean String Unit Printing and Debugging Bindings Mutation and Refs Blocks Block Scoping Conditionals Switches Loops Putting It All Together Final Thoughts Chapter 2: Functions Defining and Using Functions Type Annotations Using Standard Library Functions and Opening Modules Higher-Order Functions Piping Labeled and Optional Parameters Currying and Partial Application Polymorphic Functions Pure Functions Ignoring Return Values Recursion Syntax How to Use Recursion Final Thoughts Chapter 3: Composite Data Types Tuples Creating Tuples Accessing Tuples Pattern Matching with Tuples Variants Declaring and Constructing Variants Pattern Matching with Variants Exhaustiveness Complex Patterns Variants with Data Recursive Data Types Options Pattern Matching Options Exceptions and Error Handling Raising Exceptions Catching Exceptions Custom Exceptions Another Way to Handle Errors: Result Result in Action Defining Errors for Results Composing Results Final Thoughts Chapter 4: Records and Objects Records Declaring and Creating Records Nominal Typing Accessing Record Fields Updating Records Mutable Fields Optional Fields Destructuring Records Pattern Matching with Records Records and Variants Printing Records Records and JSON Serialization Deserialization Objects Declaring and Creating Objects Accessing Object Fields Structural Typing Mutating Objects Printing Objects Objects and JSON Serializing Objects Deserializing Objects Objects vs. Records Chapter 5: Lists and Arrays Arrays Array Standard Library Note on Accessing Arrays Higher-Order Functions for Arrays Map Filter Reduce Composing Higher-Order Functions Higher-Order Functions in Action Generalizing Higher-Order Functions Lists Building a List Immutability and Lists Pattern Matching with List Higher-Order Functions with Lists Drawbacks of Lists Use Cases for Immutable Collections Lists vs. Arrays Final Thoughts Chapter 6: Collections Immutable Collections Immutable Sets Creating a Set Updating a Set Common Set Operations Immutable Maps Creating a Map Updating a Map Accessing a Map Using Collections: Luggage Example Revisited Advanced Topic: Generic Collections Mutable Collections Mutable Stack Mutable Queue Mutable Set and Mutable Map Mutable Map Example Hash Set and Hash Map Creating a Hash Set/Hash Map Accessing Hash Maps Hash Map Example Advanced Topic: Generic Hash Set/Hash Map Keys Dict Creating a Dict Accessing a Dict Updating a Dict Serializing a Dict Which Collection Should I Use? Chapter 7: Modules Files as Modules Defining Modules Using Modules Opening Modules Destructuring a Module Module Examples Module Signatures Interface Files Defining Module Signatures Functors Defining and Using Functors Extending Modules Functors in the Standard Library Final Thoughts Chapter 8: JavaScript Interoperability Calling JavaScript from ReScript Embedding Raw JavaScript in ReScript Files Calling ReScript from JavaScript Exporting Values from ReScript Using ReScript Modules from JavaScript Shared Data Types Integers Functions Options Other Data Types Immutable Data Structures Variants Polymorphic Variants Working with Null Working with Exceptions Catching ReScript Exceptions in JavaScript Catching JavaScript Exceptions in ReScript Working with JSON Option 1: Binding Without Types Option 2: Binding With Types Option 3: With Validation Putting It All Together: Simple ReScript Web App Version 1: Handwritten Bindings Client Client Bundling Server Running the Demo Version 2: Using Imported Bindings Client Server Final Thoughts Index
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/Apress
2. In the Find a repository… box, search the book title: Introducing ReScript: Functional Programming for Web Applications
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.