HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleghc-source-gen-0.4.6.0Haskell2010

GHC.SourceGen.Decl

This module provides combinators for constructing Haskell declarations.

  • 6 types
  • 1 class
  • 25 values

Type declarations

3 declarations

Data constructors

valueprefixCon :: OccNameStr -> [Field] -> ConDecl'
#

Declares a Haskell-98-style prefix constructor for a data or type declaration.

Foo a Int
=====
prefixCon "Foo" [field (var "a"), field (var "Int")]
valueinfixCon :: Field -> OccNameStr -> Field -> ConDecl'
#

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")]
datadata Field
#

An individual argument of a data constructor. Contains a type for the field, and whether the field is strict or lazy.

valuefield :: HsType' -> Field
#

A field with no explicit strictness annotations.

A b
=====
field $ var "A" @@ var "b"
valuestrict :: Field -> Field
#

Give a field an explicit strictness annotation. Overrides any such previous annotations (for example, from lazy).

!(A b)
=====
strict $ field $ var "A" @@ var "b"
valuelazy :: Field -> Field
#

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

Class declarations

3 declarations
valueclass'
  1. :: [HsType']

    Context

  2. -> OccNameStr

    Class name

  3. -> [HsTyVarBndr']

    Type parameters

  4. -> [ClassDecl]

    Class declarations

  5. -> 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")
     ]
datadata ClassDecl
#

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
valuefunDep :: [RdrNameStr] -> [RdrNameStr] -> ClassDecl
#

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 declarations
valueinstance' :: HsType' -> [RawInstDecl] -> HsDecl'
#

An 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"
      ]
  ]
datadata RawInstDecl
#

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

Pattern synonyms

3 declarations