Language Extensions
DataKinds
Promotion (aka DataKinds) allows us to automatically lift (non-GADT) datatypes to the kind level.
We define:
data Nat = Zero | Suc Nat
We can use Nat as a type and Nat as a kind.
We can use Zero and Suc as terms, and 'Zero and 'Succ as types.
The leading quote to indicate promotion is only required to resolve ambiguities and can otherwise be omitted.
code:datakind.hs
data Nat = Zero | Suc Nat
-- Normal interpretation:
Nat :: *
Zero :: Nat
Suc :: Nat -> Nat
-- Promoted interpretation:
'Zero :: Nat
'Suc ::Nat->Nat
DeriveFunctor, Foldable, Traversable
Generalized Algebraic Datatypes (GADTs)
KindSignatures
RankNTypes
Rank-2 polymorphism is quantifies a function argument.
RecordWildType
Allow the use of wildcards in record construction and pattern matching.
code:rwt.hs
data Person = Person {
name :: String
, age :: Int
}
introduce :: Person -> String
introduce Person@{..} = "Hi, I'm " ++ show name ++
". my age is " ++ show age
StandaloneDeriving
TypeApplications
Explicitly apply a type in Haskell, using the @ operator.
code:typeapplications.hs
strange :: String -> String
strange = show . read @ Int
XOverloadedStrings
Useful links