售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright and Credits
Learn Type-Driven Development
Packt Upsell
Why subscribe?
Packt.com
Contributors
About the authors
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Starting Type-Driven Development
Analyzing code for hidden errors
Adding types
ReasonML
Why ReasonML?
Getting started with ReasonML
Using Try Reason
Going further
Summary
Programming with Types and Values
Workflow
Types and values
Static types
What do you gain?
Static and dynamic environments
Values
Scoping and shadowing
Understanding type erasure
Errors
Syntax errors
Type errors and inference
Summary
Packaging Types and Values Together
File modules
Syntactic modules
Using a syntactic module
Module signatures
Exporting and documenting the public API
Syntactic module signatures
Module errors
Signature mismatch
Value can't be found
Type abstraction
Zero-allocation type abstraction
Preventing type mix-ups
Summary
Grouping Values Together in Types
Record types
Record literals
Accessing fields and dealing with errors
Changing record values
Immutable updates
Mutable record fields
Record patterns
Tuple types
Accessing tuple values
Destructuring pattern matching
Accessor functions
Object types
Inheritance and subtyping
JavaScript object types
Summary
Putting Alternative Values in Types
Variant types
Pattern matching
The power of switch
Refutable patterns
The when clause and general branching
Stricter safety checks
Polymorphic variant types
Creating and typing values
Inputting values into functions
Understanding polymorphic variant inference
Outputting values from functions
Generalized algebraic data types
Designing for correctness with types
Products and sums together
Recursive types
Summary
Making Types That Can Slot into Any Other Type
Type inference and generic types
The special case of interpolation
Type parameters
The list – modeling more than one
The option – modeling either none or one
Mutable parameterized types – ref and array
Managing a reference to a value
Managing an array of values
Mutation and type inference restrictions
Forcing a difference with phantom types
Summary
Making Types That Represent Operations
Function types and other useful properties
Referential transparency
Function purity
Totality
What a function type means
Multiple arguments and currying
Functions as values
Function literal syntax
Eta abstraction
Summary
Reusing Code with Many Different Types
Polymorphism in Reason
Generic functions with parametric polymorphism
Ad hoc polymorphism or overloading
Generic code with functors
What is a functor?
Example 1 – looking in the standard library
Example 2
Example 3
Summary
Extending Types with New Behavior
Subtyping using polymorphic variants
Reusing constructors for different types
An example of polymorphic variant type extension
More about extending polymorphic variant types
Code reuse with OOP-style inheritance
Opening a module
Including a module
Summary
Bringing It All Together
Starting with a variant type (version 1)
Using more pattern matching (version 2)
Switching to polymorphic variant types (version 3)
Using records (version 4)
Using modules for code structure (version 5)
An alternative code structure (version 6)
An improvement – using lists as output (version 7)
Another improvement – using mutable records (version 8)
Unit testing our code (final version)
Creating our final package and setting up for tests
Writing our first tests
Running the tests
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜