-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Haskell Design Patterns
By :

In this section, we will describe a series of patterns related to data abstraction. We start with existentially quantified types then progress to phantom types and end with GADTs. We'll see that these patterns are based on a spectrum of generality and power.
Let's explore existential quantification from the perspective of its opposite, universal quantification. We rely on universal quantification whenever we parameterize function types, for example:
id' :: a -> a
-- is the same as
id' :: forall a. a -> a
id' x = x
In general, universal quantification expresses parametric polymorphism in functions and datatypes. We use the forall
keyword in Rank-n
function type to indicate nested parametric polymorphism. Similarly, universal quantification is the default pattern when parameterizing types with types, as shown:
data Maybe' a = Nothing' | Just' a -- conceptually (but not...
Change the font size
Change margin width
Change background colour