Haskell98 and Haskell2010 are standards.
But GHC provides many extensions.
Extensions can be enabled with:
:set -XBinaryLiterals
(in ghci){-# LANGUAGE BinaryLiterals #-}
(in code)EmptyCase
Allow to pattern match with case
on a type without
constructors.
Eg:
data Void = Void
f :: Void -> Int
= case x of { } f x
DeriveLift
Lift
class for types via
deriving
clauseExplicitForAll
Implied by: ScopedTypeVariables, LiberalTypeSynonyms, RankNTypes, ExistentialQuantification
Even without this extension, there is a forall
by
default.
For example, foo :: a -> a
really means
foo :: forall a. (a -> a)
(but the latter makes scoped
type variables via ScopedTypeVariables
possible).
ExplicitForAll
can give more control over this implicit
quantification.
ScopedTypeVariables
Allows free variables (introduced with a forall
)
occuring in the type to be 're-used' in type annotations in the body of
a definition.
Example from Haskell wiki:
{-# LANGUAGE ScopedTypeVariables #-}
f :: forall a. [a] -> [a]
f xs = ys ++ ys
where
ys :: [a] -- This `a` is same the one in type of `f'
ys = reverse xs
See: https://wiki.haskell.org/Scoped_type_variables
Apparently can help avoid monomorphism restriction.
UnicodeSyntax
Allows using unicode symbols in place of certain character sequences.
Like:
∀
instead of forall
→
instead of ->
StandaloneDeriving
Allow a shorter form of instance definition of a type class for an type that has already been defined.
data Foo a = Bar a | Baz String
deriving instance Eq a => Eq (Foo a)
For types for which haskell can make the derivation by itself. Otherwise we would have to write the instance definition ourselves.
Standalone deriving is similar to having a deriving
clause made as part of a type's definition, but not exactly same.
deriving
clause, standalone deriving needn't be
in same module as type definition.MagicHash
Allow definition (and use?) of identifiers with a #
at
its end.
Like: Word#
Variables with #
in end are usually used by
internals.
For example, types with #
at its end are unboxed
types by convention (not a requirement though).
BinaryLiterals
Allows use of binary notation to represent integers.
$ ghci
GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help
λ> {-# LANGUAGE BinaryLiterals #-}
λ> 0b101
5
λ> 0b1001010101011
4779
λ> 0b2031
<interactive>:4:2: error: Variable not in scope: b2031
(Couldn't get this working in ghci v8.8.4 for some reason. Though docs say it is available since v7.10.1)
Note that octal and hexadecimal notations are supported without any extensions:
λ> 0x2e
46
λ> 0o70
56
Also see: link
MultiWayIf
Use guards syntax of pattern matching in if
statements.