Repository files navigation Introduction to Haskell Types
Introduction to algebraic data types
Record syntax, fields, and functions
Product types (constructors with more than one argument)
Sum types (tagged unions)
Polymorphic types (product and sum)
Exploiting the type system
Introduction to Algebraic Data Types
The data keyword
Type constructors vs. data constructors
Type constructors are used in type signatures
Data constructors are used in patterns and code
Record Syntax, Fields, and Functions
Records look sort of like a C struct
Fields turn into functions
Record update syntax (sucks)
Data constructors that have more than one type
Records with more than one field are product types
Pattern matching to get the fields
Multiple data constructors
Canonical example: Bool = False | True
Compared to a C enum
Pattern matching on all data constructors
The type constructor uses type variables
The Maybe and Either types
Binary tree example
Exploiting the Type System
Preventing SQL injection attacks
Software Transactional Memory
You can’t perform that action at this time.