万本电子书0元读

万本电子书0元读

顶部广告

Learn Type-Driven Development电子书

售       价:¥

0人正在读 | 0人评论 9.8

作       者:Yawar Amin

出  版  社:Packt Publishing

出版时间:2018-12-26

字       数:21.4万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
A fast paced guide for JavaScript developers for writing safe, fast, and reusable code by leveraging ResaonML's strong static type system Key Features *Reduce code errors with the power of type systems *Employ static typechecking and genericity to promote code reuse and consistency *Understand functional programming which is the foundation of type-driven development Book Description Type-driven development is an approach that uses a static type system to achieve results including safety and efficiency. Types are used to express relationships and other assumptions directly in the code, and these assumptions are enforced by the compiler before the code is run. Learn Type-Driven Development covers how to use these type systems to check the logical consistency of your code. This book begins with the basic idea behind type-driven development. You’ll learn about values (or terms) and how they contrast with types. As you progress through the chapters, you’ll cover how to combine types and values inside modules and build structured types out of simpler ones. You’ll then understand how to express choices or alternatives directly in the type system using variants, polymorphic variants, and generalized algebraic data types. You’ll also get to grips with sum types, build sophisticated data types from generics, and explore functions that express change in the types of values. In the concluding chapters, you’ll cover advanced techniques for code reuse, such as parametric polymorphism and subtyping. By end of this book, you will have learned how to iterate through a type-driven process of solving coding problems using static types, together with dynamic behavior, to obtain more safety and speed. What you will learn *Use static types to capture information, making programs safer and faster *Learn ReasonML from experienced type-driven developers *Enhance safety by simply using basic types *Understand the most important type-driven concepts with simple examples *Explore a design space using static typing and find the best way to express your system rules *Use static types and dynamic runtime in harmony to write even safer and faster code Who this book is for If you’re a programmer working with dynamically typed languages and are looking for ways to mitigate production runtime errors, Learn Type-Driven Development is for you. You’ll also find this book helpful if you’re a programmer working with statically typed languages looking for increased safety and improved performance.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部