From 972bf19634b41cd981d06e47297137ee17c161f8 Mon Sep 17 00:00:00 2001 From: Pedro Correa Date: Wed, 14 Jun 2023 22:18:17 -0300 Subject: [PATCH] :sparkles: using semigroup for Structure on haskell blog --- Haskell/blog/Html.hs | 1 - Haskell/blog/Html/Internal.hs | 7 +++---- Haskell/blog/Main.hs | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Haskell/blog/Html.hs b/Haskell/blog/Html.hs index 444117e..27c14e7 100644 --- a/Haskell/blog/Html.hs +++ b/Haskell/blog/Html.hs @@ -8,7 +8,6 @@ module Html , body_ , head_ , title_ - , append_ , render ) where diff --git a/Haskell/blog/Html/Internal.hs b/Haskell/blog/Html/Internal.hs index 512a358..9ea30fd 100644 --- a/Haskell/blog/Html/Internal.hs +++ b/Haskell/blog/Html/Internal.hs @@ -8,6 +8,9 @@ newtype Structure = Structure String type Title = String +instance Semigroup Structure where + (<>) c1 c2 = Structure (getStructuredString c1 <> getStructuredString c2) + -- * EDSL html_ :: Title -> Structure -> Html @@ -31,10 +34,6 @@ p_ = Structure . el "p" . escape h1_ :: String -> Structure h1_ = Structure . el "h1" . escape -append_ :: Structure -> Structure -> Structure -append_ c1 c2 = Structure (getStructuredString c1 ++ getStructuredString c2) - - ul_ :: [Structure] -> Structure ul_ = list "ul" diff --git a/Haskell/blog/Main.hs b/Haskell/blog/Main.hs index dcef8bd..fa740a9 100644 --- a/Haskell/blog/Main.hs +++ b/Haskell/blog/Main.hs @@ -7,10 +7,10 @@ main = putStrLn $ render $ html_ "My page title" - ( append_ - (h1_ "Hello World!") - ( append_ - (p_ "Paragraph #1") + ( + (h1_ "Hello World!") <> + ( + (p_ "Paragraph #1") <> (p_ "Paragraph #2") ) ) -- 2.51.2