HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulelucid-2.11.20230408Haskell2010

Lucid.Base

Base types and combinators.

  • 3 types
  • 4 classes
  • 14 values

Rendering

5 declarations

Running

5 declarations
valueexecHtmlT
  1. :: Monad m
  2. => HtmlT m a

    The HTML to generate.

  3. -> m Builder

    The a is discarded.

#

Build the HTML. Analogous to execState.

You might want to use this is if you want to do something with the raw Builder. Otherwise for simple cases you can just use renderText or renderBS.

valueevalHtmlT
  1. :: Monad m
  2. => HtmlT m a

    HTML monad to evaluate.

  3. -> m a

    Ignore the HTML output and just return the value.

#

Evaluate the HTML to its return value. Analogous to evalState.

Use this if you want to ignore the HTML output of an action completely and just get the result.

For using with the Html type, you'll need runIdentity e.g.

Example1 expression
runIdentity (evalHtmlT (p_ "Hello!"))()
valuerunHtmlT :: HtmlT m a -> m (Seq Attribute -> Builder, a)
#

This is the low-level way to run the HTML transformer, finally returning an element builder and a value. You can pass mempty for this argument for a top-level call. See evalHtmlT and execHtmlT for easier to use functions.

valuerelaxHtmlT
  1. :: Monad m
  2. => HtmlT Identity a

    The HTML generated purely.

  3. -> HtmlT m a

    Same HTML accessible in a polymorphic context.

#

Generalize the underlying monad.

Some builders are happy to deliver results in a pure underlying monad, here Identity, but have trouble maintaining the polymorphic type. This utility generalizes from Identity.

valuecommuteHtmlT
  1. :: (Functor m, Monad n)
  2. => HtmlT m a

    unpurely generated HTML

  3. -> m (HtmlT n a)

    Commuted monads. Note: n can be Identity

#

Commute inner m to the front.

This is useful when you have impure HTML generation, e.g. using StateT. Recall, there is `MonadState s HtmlT` instance.

exampleHtml :: MonadState Int m => HtmlT m ()
exampleHtml = ul_ $ replicateM_ 5 $ do
  x <- get
  put (x + 1)
  li_ $ toHtml $ show x

exampleHtml' :: Monad m => HtmlT m ()
exampleHtml' = evalState (commuteHtmlT exampleHtml) 1

Combinators

4 declarations

Types

3 declarations
typetype Html = HtmlT Identity
#

Simple HTML builder type. Defined in terms of HtmlT. Check out that type for instance information.

Simple use-cases will just use this type. But if you want to transformer over Reader or something, you can go and use HtmlT.

newtypenewtype HtmlT (m :: Type -> Type) a
#

A monad transformer that generates HTML. Use the simpler Html type if you don't want to transform over some other monad.

Don't rely on the internal representation of this type. Use the monad and functor classes.

Constructors

Instances22MonadTrans, MFunctor, MonadError, MonadReader, MonadState, MonadWriter, …
datadata Attribute
#

A simple attribute. Don't use the constructor, use makeAttribute. Attributes are case sensitive, so if you want attributes to be merged properly, use a single case representation.

Constructors

Instances7Eq, Show, Hashable, Term, TermRaw, …

Classes

4 declarations
classclass Term arg result | result -> arg where
#

Used to construct HTML terms.

Simplest use: p_ = term "p" yields p_.

Very overloaded for three cases:

  • The first case is the basic arg of [(Text,Text)] which will return a function that wants children.

  • The second is an arg which is HtmlT m (), in which case the term accepts no attributes and just the children are used for the element.

  • Finally, this is also used for overloaded attributes, like style_ or title_. If a return type of (Text,Text) is inferred then an attribute will be made.

The instances look intimidating but actually the constraints make it very general so that type inference works well even in the presence of things like OverloadedLists and such.

Methods

  • term :: Text -> arg -> result

    Used for constructing elements e.g. term "p" yields p_.

  • termWith :: Text -> [Attribute] -> arg -> result

    Use this if you want to make an element which inserts some pre-prepared attributes into the element.

Instances3Term
  • Term Text AttributeDefined in lucid-2.11.20230408 · Lucid.Base

    Some terms (like style_, title_) can be used for attributes as well as elements.

  • (Applicative m, f ~ HtmlT m a) => Term [Attribute] (f -> HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base

    Given attributes, expect more child input.

  • Applicative m => Term (HtmlT m a) (HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base

    Given children immediately, just use that and expect no attributes.

classclass TermRaw arg result | result -> arg where
#

Same as the Term class, but will not HTML escape its children. Useful for elements like style_ or script_.

Methods

  • termRaw :: Text -> arg -> result

    Used for constructing elements e.g. termRaw "p" yields p_.

  • termRawWith :: Text -> [Attribute] -> arg -> result

    Use this if you want to make an element which inserts some pre-prepared attributes into the element.

Instances3TermRaw
  • TermRaw Text AttributeDefined in lucid-2.11.20230408 · Lucid.Base

    Some termRaws (like style_, title_) can be used for attributes as well as elements.

  • (Monad m, a ~ ()) => TermRaw Text (HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base

    Given children immediately, just use that and expect no attributes.

  • (Monad m, ToHtml f, a ~ ()) => TermRaw [Attribute] (f -> HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base

    Given attributes, expect more child input.

classclass ToHtml a where
#

Can be converted to HTML.

Methods

Instances6ToHtml
  • ToHtml ByteStringDefined in lucid-2.11.20230408 · Lucid.Base

    This instance requires the ByteString to contain UTF-8 encoded text, for the toHtml method. The toHtmlRaw method doesn't care, but the overall HTML rendering methods in this module assume UTF-8.

  • ToHtml ByteStringDefined in lucid-2.11.20230408 · Lucid.Base

    This instance requires the ByteString to contain UTF-8 encoded text, for the toHtml method. The toHtmlRaw method doesn't care, but the overall HTML rendering methods in this module assume UTF-8.

  • ToHtml StringDefined in lucid-2.11.20230408 · Lucid.Base
  • ToHtml TextDefined in lucid-2.11.20230408 · Lucid.Base
  • ToHtml TextDefined in lucid-2.11.20230408 · Lucid.Base
  • (a ~ (), m ~ Identity) => ToHtml (HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base
classclass With a where
#

With an element use these attributes. An overloaded way of adding attributes either to an element accepting attributes-and-children or one that just accepts attributes. See the two instances.

Methods

  • with :: a -> [Attribute] -> a

    With the given element(s), use the given attributes.

Instances2With
  • Functor m => With (HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base

    For the contentless elements: br_

  • Functor m => With (HtmlT m a -> HtmlT m a)Defined in lucid-2.11.20230408 · Lucid.Base

    For the contentful elements: div_