|
|
|
|
|
by Iceland_jack
1477 days ago
|
|
Oh this looks fun
getStructureString and render can be defined as record selectors newtype Structure = Structure { getStructureString :: String }
newtype Html = Html { render :: String }
BlockArguments let you write expressions like myhtml myhtml :: Html
myhtml =
html_
"My title"
( append_
(h1_ "Heading")
( append_
(p_ "Paragraph #1")
(p_ "Paragraph #2")
)
)
in a more domain-specific style. De gustibus, but some may prefer it to the parentheses. {-# Language BlockArguments #-}
myhtml :: Html
myhtml =
html_ "My title" do
append_
do h1_ "Heading"
do append_
do p_ "Paragraph #1"
do p_ "Paragraph #2"
or using the associativity of append_ = (<>) myhtml =
html_ "My title" do
h1_ "Heading" <> p_ "Paragraph #1" <> p_ "Paragraph #2"
myhtml =
html_ "My title" do mconcat
[ h1_ "Heading"
, p_ "Paragraph #1"
, p_ "Paragraph #2"
]
All examples of 'concat . map' can be replaced with.. concatMap :Ð |
|