type-of-html 1.3.1.1 → 1.3.2.0
raw patch · 7 files changed
+95/−74 lines, 7 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Html: instance Html.Document ((Html.Type.Internal.:@:) a b c) => GHC.Show.Show ((Html.Type.Internal.:@:) a b c)
- Html: instance Html.Document ((Html.Type.Internal.:@:) a b c) => GHC.Show.Show [(Html.Type.Internal.:@:) a b c]
- Html: instance Html.Document (a Html.Type.Internal.# b) => GHC.Show.Show (a Html.Type.Internal.# b)
- Html: instance Html.Document (a Html.Type.Internal.# b) => GHC.Show.Show [a Html.Type.Internal.# b]
- Html: instance Html.Document (a Html.Type.Internal.:= b) => GHC.Show.Show (a Html.Type.Internal.:= b)
+ Html: instance Html.Document a => GHC.Show.Show a
Files
- bench/Big.hs +4/−5
- bench/Medium.hs +14/−15
- bench/Small.hs +46/−44
- src/Html.hs +2/−6
- src/Html/Reify.hs +13/−2
- test/Main.hs +14/−0
- type-of-html.cabal +2/−2
bench/Big.hs view
@@ -12,12 +12,11 @@ big :: Benchmark big = bgroup "Big"- [ bench "table" $ r table (15,15)- , bench "table'" $ r table' (15,15)- , bench "page" $ r page "big"- , bench "page'" $ r page' "big"+ [ bench "table" $ nf (renderByteString . table) (15,15)+ , bench "table'" $ nf (renderByteString . table') (15,15)+ , bench "page" $ nf (renderByteString . page) "big"+ , bench "page'" $ nf (renderByteString . page') "big" ]- where r f x = nf (renderByteString . f) x table (n, m) = table_ . replicate n . tr_ $ map td_ [(1::Int)..m]
bench/Medium.hs view
@@ -15,28 +15,27 @@ medium :: Benchmark medium = bgroup "Medium"- [ bench "helloWorld" $ r helloWorld "medium"- , bench "helloWorld'" $ r helloWorld' "medium"+ [ bench "helloWorld" $ nf (renderByteString . helloWorld) "medium"+ , bench "helloWorld'" $ nf (renderByteString . helloWorld') "medium" , bench "randomString" $ nfIO randomString , bench "randomStringRaw" $ nfIO randomStringRaw , bench "randomStrictText" $ nfIO randomStrictText , bench "randomStrictTextRaw" $ nfIO randomStrictTextRaw , bench "randomLazyText" $ nfIO randomLazyText , bench "randomLazyTextRaw" $ nfIO randomLazyTextRaw- , bench "table" $ r table (2,2)- , bench "table'" $ r table' (2,2)- , bench "page" $ r page "medium"- , bench "page'" $ r page' "medium"- , bench "pageA" $ r pageA "medium"- , bench "pageA'" $ r pageA' "medium"- , bench "attrShort" $ r attrShort "medium"- , bench "attrShort'" $ r attrShort' "medium"- , bench "attrShort''" $ r attrShort'' "medium"- , bench "attrLong" $ r attrLong "medium"- , bench "attrLong'" $ r attrLong' "medium"- , bench "attrLong''" $ r attrLong'' "medium"+ , bench "table" $ nf (renderByteString . table) (2,2)+ , bench "table'" $ nf (renderByteString . table') (2,2)+ , bench "page" $ nf (renderByteString . page) "medium"+ , bench "page'" $ nf (renderByteString . page') "medium"+ , bench "pageA" $ nf (renderByteString . pageA) "medium"+ , bench "pageA'" $ nf (renderByteString . pageA') "medium"+ , bench "attrShort" $ nf (renderByteString . attrShort) "medium"+ , bench "attrShort'" $ nf (renderByteString . attrShort') "medium"+ , bench "attrShort''" $ nf (renderByteString . attrShort'') "medium"+ , bench "attrLong" $ nf (renderByteString . attrLong) "medium"+ , bench "attrLong'" $ nf (renderByteString . attrLong') "medium"+ , bench "attrLong''" $ nf (renderByteString . attrLong'') "medium" ]- where r f x = nf (renderByteString . f) x randomString = do a <- generate (resize 5 arbitrary) :: IO String
bench/Small.hs view
@@ -10,57 +10,59 @@ import Data.Proxy import qualified Data.Text as T import qualified Data.Text.Lazy as LT+import Data.IORef import Criterion.Main import Control.Arrow small :: Benchmark small = bgroup "Small"- [ bench "oneElement" $ r oneElement ""- , bench "oneElement'" $ r oneElement' ""- , bench "oneElement''" $ r oneElement'' ""- , bench "nestedElement" $ r nestedElement ""- , bench "nestedElement'" $ r nestedElement' ""- , bench "nestedElement''" $ r nestedElement'' ""- , bench "parallelElement" $ r parallelElement ""- , bench "parallelElement'" $ r parallelElement' ""- , bench "parallelElement''" $ r parallelElement'' ""- , bench "listElement" $ r listElement ""- , bench "listElement'" $ r listElement' ""- , bench "listElement''" $ r listElement'' ""- , bench "Int" $ r id (123456789 :: Int)- , bench "Integer" $ r id (123456789 :: Integer)- , bench "Double" $ r id (123456789 :: Double)- , bench "Float" $ r id (123456789 :: Float)- , bench "Word" $ r id (123456789 :: Word)- , bench "Proxy" $ r id (Proxy :: Proxy "abc")- , bench "Char" $ r id 'a'- , bench "oneElement Proxy" $ r oneElement (Proxy :: Proxy "abc")- , bench "()" $ r id ()- , bench "oneElement ()" $ r oneElement ()- , bench "oneAttribute" $ r A.class_ ""- , bench "oneAttribute ()" $ r A.class_ ()- , bench "oneAttribute Proxy" $ r A.class_ (Proxy :: Proxy "abc")- , bench "parallelAttribute" $ r (\x -> A.class_ x # A.id_ x) ""- , bench "elementWithAttribute" $ r (\x -> div_A (A.class_ x) x) ""- , bench "elementWithParallelAttribute" $ r (\x -> div_A (A.class_ x # A.id_ x) x) ""- , bench "listOfAttributes" $ r (\x -> [A.class_ x, A.class_ x]) ""- , bench "Runtime String" $ r id runtimeTxt- , bench "String" $ r id "abcdefghijklmnopqrstuvwxyz<>&;"- , bench "Runtime Raw String" $ r id (Raw runtimeTxt)- , bench "Raw String" $ r id (Raw "abcdefghijklmnopqrstuvwxyz<>&;")- , bench "Runtime strict Text" $ r id (T.pack runtimeTxt)- , bench "strict Text" $ r id (T.pack "abcdefghijklmnopqrstuvwxyz<>&;")- , bench "Runtime Raw strict Text" $ r id (Raw (T.pack runtimeTxt))- , bench "Raw strict Text" $ r id (Raw (T.pack "abcdefghijklmnopqrstuvwxyz<>&;"))- , bench "Runtime lazy Text" $ r id (LT.pack runtimeTxt)- , bench "lazy Text" $ r id (LT.pack "abcdefghijklmnopqrstuvwxyz<>&;")- , bench "Runtime Raw lazy Text" $ r id (Raw (LT.pack runtimeTxt))- , bench "Raw lazy Text" $ r id (Raw (LT.pack "abcdefghijklmnopqrstuvwxyz<>&;"))- , bench "listOfListOf" $ r (\x -> div_ [i_ [span_ x]]) ""+ [ bench "oneElement" $ nf (renderByteString . oneElement) ""+ , bench "oneElement'" $ nf (renderByteString . oneElement') ""+ , bench "oneElement''" $ nf (renderByteString . oneElement'') ""+ , bench "nestedElement" $ nf (renderByteString . nestedElement) ""+ , bench "nestedElement'" $ nf (renderByteString . nestedElement') ""+ , bench "nestedElement''" $ nf (renderByteString . nestedElement'') ""+ , bench "parallelElement" $ nf (renderByteString . parallelElement) ""+ , bench "parallelElement'" $ nf (renderByteString . parallelElement') ""+ , bench "parallelElement''" $ nf (renderByteString . parallelElement'') ""+ , bench "listElement" $ nf (renderByteString . listElement) ""+ , bench "listElement'" $ nf (renderByteString . listElement') ""+ , bench "listElement''" $ nf (renderByteString . listElement'') ""+ , bench "Int" $ nf renderByteString (123456789 :: Int)+ , bench "Integer" $ nf renderByteString (123456789 :: Integer)+ , bench "Double" $ nf renderByteString (123456789 :: Double)+ , bench "Float" $ nf renderByteString (123456789 :: Float)+ , bench "Word" $ nf renderByteString (123456789 :: Word)+ , bench "Proxy" $ nf renderByteString (Proxy :: Proxy "abc")+ , bench "Char" $ nf renderByteString 'a'+ , bench "oneElement Proxy" $ nf (renderByteString . oneElement) (Proxy :: Proxy "abc")+ , bench "()" $ nf renderByteString ()+ , bench "oneElement ()" $ nf (renderByteString . oneElement) ()+ , bench "oneAttribute" $ nf (renderByteString . A.class_) ""+ , bench "oneAttribute ()" $ nf (renderByteString . A.class_) ()+ , bench "oneAttribute Proxy" $ nf (renderByteString . A.class_) (Proxy :: Proxy "abc")+ , bench "parallelAttribute" $ nf (\x -> renderByteString $ A.class_ x # A.id_ x) ""+ , bench "elementWithAttribute" $ nf (\x -> renderByteString $ div_A (A.class_ x) x) ""+ , bench "elementWithParallelAttribute" $ nf (\x -> renderByteString $ div_A (A.class_ x # A.id_ x) x) ""+ , bench "listOfAttributes" $ nf (\x -> renderByteString [A.class_ x, A.class_ x]) ""+ , bench "Runtime String" $ nfIO (renderByteString <$> runtimeTxt)+ , bench "String" $ nf renderByteString "abcdefghijklmnopqrstuvwxyz<>&;"+ , bench "Runtime Raw String" $ nfIO (renderByteString . Raw <$> runtimeTxt)+ , bench "Raw String" $ nf renderByteString (Raw "abcdefghijklmnopqrstuvwxyz<>&;")+ , bench "Runtime strict Text" $ nfIO (renderByteString . T.pack <$> runtimeTxt)+ , bench "strict Text" $ nf renderByteString (T.pack "abcdefghijklmnopqrstuvwxyz<>&;")+ , bench "Runtime Raw strict Text" $ nfIO (renderByteString . Raw . T.pack <$> runtimeTxt)+ , bench "Raw strict Text" $ nf renderByteString (Raw (T.pack "abcdefghijklmnopqrstuvwxyz<>&;"))+ , bench "Runtime lazy Text" $ nfIO (renderByteString . LT.pack <$> runtimeTxt)+ , bench "lazy Text" $ nf renderByteString (LT.pack "abcdefghijklmnopqrstuvwxyz<>&;")+ , bench "Runtime Raw lazy Text" $ nfIO (renderByteString . Raw . LT.pack <$> runtimeTxt)+ , bench "Raw lazy Text" $ nf renderByteString (Raw (LT.pack "abcdefghijklmnopqrstuvwxyz<>&;"))+ , bench "listOfListOf" $ nf (\x -> renderByteString $ div_ [i_ [span_ x]]) "" ]- where r f x = nf (renderByteString . f) x- runtimeTxt = reverse "abcdefghijklmnopqrstuvwxyz<>&;"+ where++runtimeTxt = newIORef "abcdefghijklmnopqrstuvwxyz<>&;" >>= readIORef oneElement, oneElement', oneElement'' :: ('Div ?> a)
src/Html.hs view
@@ -52,9 +52,5 @@ renderByteString :: Document a => a -> B.ByteString renderByteString = B.toLazyByteString . renderBuilder --- | Orphan show instances to faciliate ghci development.-instance Document ((a :@: b) c) => Show ((a :@: b) c) where show = renderString-instance {-# OVERLAPPING #-} Document ((a :@: b) c) => Show [(a :@: b) c] where show = renderString-instance Document (a := b) => Show (a := b) where show = renderString-instance Document (a # b) => Show (a # b) where show = renderString-instance {-# OVERLAPPING #-} Document (a # b) => Show [a # b] where show = renderString+-- | Orphan show instance to faciliate ghci development.+instance {-# OVERLAPPABLE #-} Document a => Show a where show = renderString
src/Html/Reify.hs view
@@ -49,6 +49,11 @@ {-# INLINE render #-} render (T x) = convert x +instance {-# OVERLAPPING #-}+ R (T '[ EmptySym ] String) where+ {-# INLINE render #-}+ render (T x) = convert x+ instance ( Convert b , R (Proxy s)@@ -64,6 +69,12 @@ render (T x) = render (Proxy @ s) <> convert x instance {-# OVERLAPPING #-}+ ( R (Proxy s)+ ) => R (T '[s] String) where+ {-# INLINE render #-}+ render (T x) = render (Proxy @ s) <> convert x++instance {-# OVERLAPPING #-} ( R (T xs val) ) => R (T (NoTail xs) val) where {-# INLINE render #-}@@ -95,9 +106,9 @@ <> render (T b :: T (Drop (Length a) ps) b) instance- ( R (T (ToList (a `f` b)) (a `f` b))+ ( R (T (ToList a) a) , R (Proxy s)- ) => R (T (s ': ss) [a `f` b]) where+ ) => R (T (s ': ss) [a]) where {-# INLINE render #-} render (T xs) = render (Proxy @ s)
test/Main.hs view
@@ -271,3 +271,17 @@ renderString (div_ () # td_ (Proxy @"1" # "2" # div_ () # i_A (A.id_ (Proxy @"3")) "4")) `shouldBe` "<div></div><td>12<div></div><i id=\"3\">4</i></td>"++ it "handles list of convertibles" $ do++ renderString (div_ [1..5 :: Int])+ `shouldBe`+ "<div>12345</div>"++ renderString [1..5 :: Int]+ `shouldBe`+ "12345"++ renderString (div_ ["abc"])+ `shouldBe`+ "<div>abc</div>"
type-of-html.cabal view
@@ -1,5 +1,5 @@ name: type-of-html-version: 1.3.1.1+version: 1.3.2.0 synopsis: High performance type driven html generation. description: This library makes most invalid html documents compile time errors and uses advanced type level features to realise compile time computations. license: BSD3@@ -56,7 +56,7 @@ , Big , Blaze hs-source-dirs: bench- ghc-options: -Wall -O0+ ghc-options: -Wall -O2 default-language: Haskell2010 build-depends: base >= 4.9 && < 5 , type-of-html