3

I'm working with blaze-html. I'm finally mostly being able to wrap my head around how to use it, but some of the monads and transformations really trip me up all the time. But here is one particular stumbling block (out of a great many, but I'll leave for another day getting from here to Happstack's Response and ServerPart monads).

If I'm wanting to attach string text to a paragraph, I have to use this function (from Text.Blaze.Html5):

p . toHtml :: ToMessage a => a -> Html

All, well and good, except...

toHtml :: ToMarkup a => a -> Markup
p :: Html -> Html

I've searched the documentation to the best of my ability, and I cannot see how the Markup monad and the Html monad are associated with one another. How do I work through all of the types and typeclasses?

Savanni D'Gerinel
  • 2,379
  • 17
  • 27

1 Answers1

6

They are synonyms (i.e. they are the same type), as shown in the documentation.

Also, it is not correct to call these types monads. They are just types. They are, however, constructed from a monad (MarkupM).

As a quick check, something can be called a monad if it is a type parameterised by another type (has kind * -> *). This is a necessary (but not sufficient) condition.

Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121
  • Odd. I started on the Text-Blaze-Html5.html in my local cabal/haddock documentation, and the Html link actually points me to Text-Blaze-Internal.html. From there, Html is defined as HtmlM (), which itself is defined as ``data HtmlM a`` with a lot of instances. None of the links point to the definition in Text.Blaze.Html. – Savanni D'Gerinel Sep 21 '12 at 21:01
  • Perhaps you have an older version of the library? – Roman Cheplyaka Sep 21 '12 at 21:02
  • The docs seem to be from an older version, @SavanniD'Gerinel, in blaze-html-0.4.*, the type of `toHtml` was `ToHtml a => a -> Html`, and there was no `Markup` there. – Daniel Fischer Sep 21 '12 at 21:18
  • I dug in and both Daniel Fischer and Roman Cheplyaka are right. I am running 0.5.0, but the haddock documentation that cabal put in my documentation index is for 0.4.3, even after installing 0.5.1. This probably is yet further evidence that I rely too much on cabal as a [package manager](http://ivanmiljenovic.wordpress.com/2010/03/15/repeat-after-me-cabal-is-not-a-package-manager/) – Savanni D'Gerinel Sep 21 '12 at 21:57
  • 2
    Ah, I see. This is a known bug somewhere (in the Cabal library, if I'm not mistaken), which is fixed in the fresh ghc release. The bug is that instead of the newest version, the oldest one is taken to generate a local documentation index. You can work around it by doing `ghc-pkg unregister blaze-html-0.4.3` and then reinstalling the new version. Or you can find the docs for the right version directly in `~/.cabal/share/doc`. – Roman Cheplyaka Sep 21 '12 at 22:11