Advanced types and FFI
The type system of Haskell goes further than a signature of one arrow, and these twelve lessons use it: GADTs, type families, rank-N types, the existential, kinds and DataKinds, the deriving strategies and DerivingVia. The last lessons cross the boundary to C: foreign import ccall, foreign export, the shared library a C driver calls, and the same library read from Python. A parser closes the part.
7.1
GADTs
data ... where, a constructor with a refined result type, a typed expression
Open
7.2
Type families
a type family, an associated type, an instance per type, TypeFamilies
Open
7.3
Rank-N types
forall inside a type, RankNTypes, a function that takes a polymorphic argument
Open
7.4
Existential types
forall a. in a constructor, a heterogeneous list, the operation it keeps
Open
7.5
Kinds and DataKinds
:kind, a kind signature, promoted constructors, a phantom that carries units
Open
7.6
Deriving strategies
deriving stock, newtype and anyclass, GeneralizedNewtypeDeriving, what each one means
Open
7.7
DerivingVia
deriving via, a newtype wrapper with a shared instance, DerivingVia
Open
7.8
Phantom types
a type parameter that carries no value, a checked transition, DataKinds with it
Open
7.9
Calling C from Haskell
foreign import ccall, a C function, Ptr, CString, the link line
Open
7.10
Being called from C
foreign export ccall, a shared library, a C driver, the stable pointer question
Open
7.11
Calling Haskell from Python
the same shared library through ctypes, a measured call, the string lifetime
Open
7.12
Parsing with parsec
Parser, parse, char, string, many, a small grammar, the error position
Open