Moduleghc-source-gen-0.4.6.0Haskell2010
GHC.SourceGen.Decl
This module provides combinators for constructing Haskell declarations.
- 6 types
- 1 class
- 25 values
- Packageghc-source-gen-0.4.6.0
- Exports32
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceDecl.hs
Type declarations
3 declarationsDeclares a type synonym.
type A a b = B b a
=====
type' "A" [bvar "a", bvar "b"] $ var "B" @@ var "b" @@ var "a"A newtype declaration.
newtype Const a b = Const a deriving Eq
=====
newtype' "Const" [bvar "a", bvar "b"]
(conDecl "Const" [var "a"])
[var "Show"]A data declaration.
data Either a b = Left a | Right b
deriving Show
=====
data' "Either" [bvar "a", bvar "b"]
[ conDecl "Left" [var "a"]
, conDecl "Right" [var "b"]
]
[var "Show"]Data constructors
Declares a Haskell-98-style prefix constructor for a data or type declaration.
Foo a Int
=====
prefixCon "Foo" [field (var "a"), field (var "Int")]Declares a Haskell-98-style infix constructor for a data or type declaration.
A b :+: C d
=====
infixCon (field (var "A" @@ var "b")) ":+:" (field (Var "C" @@ var "d"))Declares Haskell-98-style record constructor for a data or type declaration.
A { x :: B, y :: C }
=====
recordCon "A" [("x", var "B"), ("y", var "C")]An individual argument of a data constructor. Contains a type for the field, and whether the field is strict or lazy.
A field with no explicit strictness annotations.
A b
=====
field $ var "A" @@ var "b"Give a field an explicit strictness annotation. Overrides any such previous annotations (for example, from lazy).
!(A b)
=====
strict $ field $ var "A" @@ var "b"Give a field an explicit laziness annotation. This feature is useful in combination
with the StrictData extension. Overrides any such previous
annotations (for example, from strict).
!(A b)
=====
strict $ field $ var "A" @@ var "b"Deriving clauses
A DerivingVia clause.
deriving (Eq, Show) via T
=====
derivingVia (var "T") [var "Eq", var "Show"]Available with ghc>=8.6.
Class declarations
3 declarationsclass' :: [HsType']Context
-> OccNameStrClass name
-> [HsTyVarBndr']Type parameters
-> [ClassDecl]Class declarations
-> HsDecl'
A class declaration.
class (Real a, Enum a) => Integral a where
divMod :: a -> a -> (a, a)
div :: a -> a -> a
div x y = fst (divMod x y)
=====
let a = var "a"
in class'
[var "Real" @@ a, var "Enum" @@ a]
"Integral"
[bvar "a"]
[ typeSig "divMod" $ a --> a --> tuple [a, a]
, typeSig "div" $ a --> a --> a
, funBind "div"
$ match [bvar "x", bvar "y"]
$ var "fst" @@ (var "divMod" @@ var "x" @@ var "y")
]A definition that can appear in the body of a class declaration.
ClassDecl definitions may be constructed using funDep or using the instance of HasValBind. For more details, see the documentation of that function, and of GHC.SourceGen.Binds overall.
Instances1HasValBind
HasValBind ClassDeclDefined in ghc-source-gen-0.4.6.0 · GHC.SourceGen.Decl
A functional dependency for a class.
| a, b -> c
=====
funDep ["a", "b"] ["c"]class Ident a b | a -> b, b -> a where
ident :: a -> b
=====
class' [] "Ident" ["a", "b"]
[ funDep ["a"] ["b"]
, funDep ["b"] ["a"]
, typeSig "ident" $ var "a" --> var "b"
]Instance declarations
4 declarationsAn instance declaration.
instance Show Bool where
show :: Bool -> String -- Requires the InstanceSigs extension
show True = "True"
show False = "False"
=====
instance' (var "Show" @@ var "Bool")
[ typeSig "show" $ var "Bool" --> var "String"
, funBinds "show"
[ match [bvar "True"] $ string "True"
, match [bvar "False"] $ string "False"
]
]A definition that can appear in the body of an instance declaration.
RawInstDecl definitions may be constructed using its class instances, e.g., HasValBind. For more details, see the documentation of those classes.
Instances2HasValBind, HasTyFamInst
HasValBind RawInstDeclDefined in ghc-source-gen-0.4.6.0 · GHC.SourceGen.DeclHasTyFamInst RawInstDeclDefined in ghc-source-gen-0.4.6.0 · GHC.SourceGen.Decl
Terms which can contain a type instance declaration.
To use this class, call tyFamInst.
Methods
tyFamInstD :: TyFamInstDecl' -> t
Instances2HasTyFamInst
HasTyFamInst RawInstDeclDefined in ghc-source-gen-0.4.6.0 · GHC.SourceGen.DeclHasTyFamInst HsDecl'Defined in ghc-source-gen-0.4.6.0 · GHC.SourceGen.Decl
A type family instance.
type Elt String = Char
=====
tyFamInst "Elt" [var "String"] (var "Char")Pattern synonyms
3 declarationsDeclares multiple pattern signatures of the same type.
pattern F, G :: T
=====
patSynSigs ["F", "G"] $ var "T"Declares a pattern signature and its type.
pattern F :: T
=====
patSynSigs "F" $ var "T"Defines a pattern signature.
pattern F a b = G b a
=====
patSynBind "F" ["a", "b"] $ conP "G" [bvar "b", bvar "a"]