FunDecl captures function declarations along with any associated linkage required.
Everything needed to make a function declaration either at top-level or inside a let block,
or to extract the function body as an expression is captured as a FunDecl
.
Options
can be applied when extracting a FunDecl
as generated code; to rename it,
to include or exclude it from the exposings, to modify or disable its docs, to include
a function signature or not.
This allows the decision to build a function as a top-level, a let expression or to extract it as an expression for further manipulation, to be deferred.
Code that writes function can therefore be used in many different ways as a result, and there is no need to write specialized cases for all the different ways in which a code generated function can be used.
( FunDecl
, Elm.CodeGen.Linkage
)
A generated function with its linkage.
{ doc : Maybe (Elm.CodeGen.Comment Elm.CodeGen.DocComment)
, sig : Maybe Elm.CodeGen.TypeAnnotation
, name : String
, args : List Elm.CodeGen.Pattern
, impl : Elm.CodeGen.Expression
}
All the parts of a function declaration.
{ name : Maybe String
, inExposings : Basics.Bool
, includeSig : Basics.Bool
, includeDoc : Basics.Bool
, altDoc : Maybe (Elm.CodeGen.Comment Elm.CodeGen.DocComment)
}
Options for generating functions.
defaultOptions : Options
The default set of options.
asTopLevel : Options -> FunGen -> ( Elm.CodeGen.Declaration, Elm.CodeGen.Linkage )
Generates a Declaration
for a function.
asLetDecl : Options -> FunGen -> ( Elm.CodeGen.LetDeclaration, Elm.CodeGen.Linkage )
Generates a LetDeclaration
for a function.
Note: As let declaractions are not visible outside of their scope, these are
never exposed, so the inExposings
option is always set to False
when using
this.
A let declaration will not have any docs or a type signature either.
asExpression : Options -> FunGen -> ( Elm.CodeGen.Expression, Elm.CodeGen.Linkage )
Generates an Expression
for a function.
Note: As the expression has not been assigned to a name, it cannot be visible
outside of the module. For this reason the inExposings
option is always set
to False
when using this. If you decide to expose the function you must add
whatever name you give it back into the linkage.
An expression will not have any docs or a type signature either.