Skip to content

Instantly share code, notes, and snippets.

@clojj
Last active Oct 18, 2019
Embed
What would you like to do?
Haskell literal Html
{-# LANGUAGE OverloadedStrings #-}
module Lib
( Html, Markup(..), html, eval
) where
eval :: Html -> String
eval (Html head body) = "<html>" ++ evalHead head ++ evalBody body ++ "</html>"
evalHead :: Head -> String
evalHead (Head resources) = "<head>" ++ concatMap evalResource resources ++ "</head>"
evalResource :: Resource -> String
evalResource resource = ""
evalBody :: Body -> String
evalBody (Body markups) = "<body>" ++ concatMap evalMarkup markups ++ "</body>"
evalMarkup :: Markup -> String
evalMarkup (Div attrs markup) = "<div" ++ concatMap evalAttr attrs ++ ">" ++ concatMap evalMarkup markup ++ "</div>"
evalMarkup (Text str) = str
evalAttr :: Attr -> String
evalAttr (name, value) = " " ++ name ++ "=\"" ++ value ++ "\""
-- model
data Html =
Html Head Body
data Head = Head [Resource]
data Resource = Resource
data Body = Body [Markup]
data Markup =
Div [Attr] [Markup]
| Text String
type Attr = (String, String)
html :: Html
html = Html
(Head [])
(Body [
Div [("class", "mystyle")]
[
Text "1"
, Text "2"
, Text "3"
]
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment