diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 48 |
1 files changed, 28 insertions, 20 deletions
@@ -3,30 +3,38 @@ | |||
3 | A true monad (transformer) version of the | 3 | A true monad (transformer) version of the |
4 | [blaze-markup](https://hackage.haskell.org/package/blaze-markup) and | 4 | [blaze-markup](https://hackage.haskell.org/package/blaze-markup) and |
5 | [blaze-html](https://hackage.haskell.org/package/blaze-html) | 5 | [blaze-html](https://hackage.haskell.org/package/blaze-html) |
6 | libraries. | 6 | libraries: |
7 | 7 | ||
8 | # Why? | 8 | > BlazeHtml is a blazingly fast HTML combinator library for the |
9 | > Haskell programming language. It embeds HTML templates in Haskell | ||
10 | > code for optimal efficiency and composability. | ||
11 | |||
12 | — from https://jaspervdj.be/blaze/. | ||
13 | |||
14 | ## What’s wrong with blaze? | ||
15 | |||
16 | Blaze’s `Markup` and `Html` **cannot be used as Monads**, let alone Monad transformers. | ||
9 | 17 | ||
10 | While blaze's `Markup` and `Html` types have `Monad` instances and can | 18 | While blaze's `Markup` and `Html` types have `Monad` instances and can |
11 | leverage the the concise `do` notation, they do not satisfy | 19 | leverage the concise `do` notation, they do not satisfy the |
12 | the | 20 | [Monad Laws](https://hackage.haskell.org/package/base-4.8.0.0/docs/Control-Monad.html#t:Monad). |
13 | [Monad Laws](https://hackage.haskell.org/package/base-4.8.0.0/docs/Control-Monad.html#t:Monad) and | ||
14 | thus cannot be used as Monads, let alone Monad transformers. | ||
15 | 21 | ||
16 | ## Use Cases | 22 | ## How do Monads help? - Use Cases |
17 | 23 | ||
18 | The `MarkupT` Monad Transformer enables us to write Markup (e.g. HTML) | 24 | The `MarkupT` Monad Transformer enables us to write Markup (e.g. HTML) |
19 | templates that have access to all those Monads you cannot live without | 25 | templates that have access to all those Monads you cannot live without |
20 | anymore. | 26 | anymore. |
21 | 27 | ||
22 | Accessing an environment | 28 | The first things that come to mind: |
23 | ([MonadReader](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Reader-Class.html)), | 29 | |
24 | accumulating log or other diagnostic output | 30 | * Accessing an environment |
31 | ([MonadReader](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Reader-Class.html)) | ||
32 | * Logging and other diagnostic output | ||
25 | ([MonadWriter](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Writer-Class.html)), | 33 | ([MonadWriter](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Writer-Class.html)), |
26 | doing `IO` (like database access) are the first things that come to | 34 | * `IO` (e.g. for database access) |
27 | mind. | 35 | |
28 | 36 | ||
29 | The reason of existence of this library is its use | 37 | The reason for the existence of this library is its use |
30 | in [Lykah](http://johannesgerer.com/Lykah), which powers my personal | 38 | in [Lykah](http://johannesgerer.com/Lykah), which powers my personal |
31 | website | 39 | website |
32 | [http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In | 40 | [http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In |
@@ -35,9 +43,9 @@ build things like menus or blog post lists) and automatically check, | |||
35 | insert and keep track of referenced pages and assets, which turns out | 43 | insert and keep track of referenced pages and assets, which turns out |
36 | to be very useful functionality of a static website generator. | 44 | to be very useful functionality of a static website generator. |
37 | 45 | ||
38 | # How to use it? | 46 | ## Usage |
39 | 47 | ||
40 | ## Backwards compatible | 48 | ### Integrating with your existing code |
41 | 49 | ||
42 | The library is intended to serve as a drop-in replacement for the | 50 | The library is intended to serve as a drop-in replacement for the |
43 | `blaze-markup` and `blaze-html` libraries and should be backwards | 51 | `blaze-markup` and `blaze-html` libraries and should be backwards |
@@ -49,7 +57,7 @@ Text.BlazeT.*` and it should give the same results. | |||
49 | For usage of blaze check out | 57 | For usage of blaze check out |
50 | their [documentation](https://jaspervdj.be/blaze/). | 58 | their [documentation](https://jaspervdj.be/blaze/). |
51 | 59 | ||
52 | ## Unleash the monads | 60 | ### Unleash the monads |
53 | 61 | ||
54 | [Text.BlazeT](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT.html) | 62 | [Text.BlazeT](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT.html) |
55 | exports `runWith` and `execWith`, which work on any | 63 | exports `runWith` and `execWith`, which work on any |
@@ -92,7 +100,7 @@ prints: | |||
92 | <p>created with blazeT at 2016-10-26 01:09:16.969147361 UTC</p> | 100 | <p>created with blazeT at 2016-10-26 01:09:16.969147361 UTC</p> |
93 | ``` | 101 | ``` |
94 | 102 | ||
95 | # Installation | 103 | ## Installation |
96 | 104 | ||
97 | 1. To make it available on your system (or sandbox) use `cabal install blazeT`. | 105 | 1. To make it available on your system (or sandbox) use `cabal install blazeT`. |
98 | 106 | ||
@@ -104,9 +112,9 @@ cabal sandbox init #optional | |||
104 | cabal install | 112 | cabal install |
105 | ``` | 113 | ``` |
106 | 114 | ||
107 | # Documentation on [Hackage](https://hackage.haskell.org/package/blazeT) | 115 | ## Documentation on [Hackage](https://hackage.haskell.org/package/blazeT) |
108 | 116 | ||
109 | # Implementation | 117 | ## Implementation |
110 | 118 | ||
111 | ... is contained | 119 | ... is contained |
112 | in | 120 | in |
@@ -116,7 +124,7 @@ Everything is build around the simple `newtype` definition of the | |||
116 | `MarkupT` transformer, which makes use | 124 | `MarkupT` transformer, which makes use |
117 | the | 125 | the |
118 | [Monoid](https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Monoid.html) instance | 126 | [Monoid](https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Monoid.html) instance |
119 | of `Blaze.Markup` and is basically a `WriterT` writing `Blaze.Markup`: | 127 | of `Blaze.Markup` and is simply a `WriterT` writing `Blaze.Markup`: |
120 | 128 | ||
121 | ```Haskell | 129 | ```Haskell |
122 | newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a } | 130 | newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a } |