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
What is the DataKinds extension of Haskell?
DeriveFunctor, Foldable, Traversable
Allowing for automatic derivation of #Functor , Foldable, and #Traversable
Generalized Algebraic Datatypes (GADTs)
See Generalized Algebraic Datatypes (GADTs)
KindSignatures
See Kinds
RankNTypes
Rank-2 polymorphism is quantifies a function argument.
See RankNTypes
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
See Literals and XOverloadedStrings
Useful links
GHC Language Features