generic-data 0.6.0.0 → 0.6.0.1
raw patch · 5 files changed
+105/−3 lines, 5 filesdep +criteriondep +deepseqdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: criterion, deepseq
Dependency ranges changed: base
API changes (from Hackage documentation)
- Generic.Data.Internal.Show: instance (Generic.Data.Internal.Show.GShowSingle Data.Functor.Identity.Identity f, Generic.Data.Internal.Show.GShowSingle p g) => Generic.Data.Internal.Show.GShowSingle p (f GHC.Generics.:.: g)
+ Generic.Data.Internal.Show: instance (Data.Functor.Classes.Show1 f, Generic.Data.Internal.Show.GShowSingle p g) => Generic.Data.Internal.Show.GShowSingle p (f GHC.Generics.:.: g)
Files
- CHANGELOG.md +4/−0
- generic-data.cabal +15/−1
- src/Generic/Data/Internal/Show.hs +2/−2
- test/bench.hs +69/−0
- test/unit.hs +15/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.6.0.1++- Fix derivation of `Show1` for `(:.:)`+ # 0.6.0.0 - Add `Surgery` newtype for DerivingVia
generic-data.cabal view
@@ -1,5 +1,5 @@ name: generic-data-version: 0.6.0.0+version: 0.6.0.1 synopsis: Deriving instances with GHC.Generics and related utilities description: Generic implementations of standard type classes.@@ -116,6 +116,20 @@ ghc-options: -Wall default-language: Haskell2010 type: exitcode-stdio-1.0++benchmark bench+ hs-source-dirs: test+ main-is: bench.hs+ build-depends:+ criterion,+ deepseq,+ generic-data,+ base+ ghc-options: -Wall+ default-language: Haskell2010+ type: exitcode-stdio-1.0+ if !impl(ghc >= 8.6)+ buildable: False source-repository head type: git
src/Generic/Data/Internal/Show.hs view
@@ -125,10 +125,10 @@ instance GShowSingle Identity Par1 where gPrecShowsSingle (Identity (showsPrec', _)) (Par1 a) = flip showsPrec' a -instance (GShowSingle Identity f, GShowSingle p g)+instance (Show1 f, GShowSingle p g) => GShowSingle p (f :.: g) where gPrecShowsSingle p (Comp1 c) =- gPrecShowsSingle (Identity (showsPrec_, showList_)) c+ flip (liftShowsPrec showsPrec_ showList_) c where showsPrec_ = flip (gPrecShowsSingle p) showList_ = showListWith (showsPrec_ 0)
+ test/bench.hs view
@@ -0,0 +1,69 @@+{-# LANGUAGE+ DeriveAnyClass,+ DeriveGeneric,+ DerivingVia,+ DerivingStrategies,+ FlexibleInstances,+ ScopedTypeVariables,+ StandaloneDeriving,+ TypeApplications+ #-}++import Data.Semigroup (Sum(..))+import GHC.Generics (Generic)+import Text.Show (showParen, showString)++import Control.DeepSeq+import Criterion.Main++import Generic.Data+import Generic.Data.Microsurgery++data H -- handwritten+data G -- generic+data S -- surgery++data T x = C { _a :: Sum Int, _b :: [Int] }+ deriving stock Generic++deriving via (Surgery Derecordify (T S)) instance Show (T S)++instance Show (T H) where+ showsPrec n (C a b) =+ showParen (n > 10)+ (showString "C "+ . showsPrec 11 a+ . showString " "+ . showsPrec 11 b)++deriving via (Generically (T G)) instance Semigroup (T G)+instance Semigroup (T H) where+ C a1 b1 <> C a2 b2 = C (a1 <> a2) (b1 <> b2)++deriving anyclass instance NFData (T G)++instance NFData (T H) where+ rnf (C a b) = rnf a `seq` rnf b `seq` ()++u :: forall x. T x+u = C 33 [99]++v :: forall x. T x+v = C 13 [14]++main :: IO ()+main = defaultMain+ [ bgroup "Show"+ [ bench "handwri" (nf show (u @H))+ , bench "surgery" (nf show (u @S))+ ]+ , bgroup "NFData"+ [ bench "handwri" (nf id (u @H))+ , bench "generic" (nf id (u @G))+ ]+ , bgroup "Semigroup"+ [ bench "baselin" (nf (uncurry (++)) ([99], [14 :: Int]))+ , bench "handwri" (nf (uncurry (<>)) (u @H, v))+ , bench "generic" (nf (uncurry (<>)) (u @G, v))+ ]+ ]
test/unit.hs view
@@ -5,6 +5,7 @@ import Control.Applicative import Data.Semigroup import Data.Monoid (Sum(..))+import Data.Functor.Classes import Test.Tasty import Test.Tasty.HUnit @@ -61,6 +62,16 @@ , SE1 True ] +-- Deriving Show1+newtype MyCompose f g a = MyCompose (f (g a))+ deriving Generic1++instance (Functor f, Show1 f, Show1 g) => Show1 (MyCompose f g) where+ liftShowsPrec = gliftShowsPrec++instance (Functor f, Show1 f, Show1 g, Show a) => Show (MyCompose f g a) where+ showsPrec = showsPrec1+ maybeModuleName :: String #if MIN_VERSION_base(4,12,0) maybeModuleName = "GHC.Maybe"@@ -132,6 +143,10 @@ , testGroup "Show" [ testCase "show" $ "P 1 2" @?= show (p' 1 2) , testCase "showsPrec" $ "(P 1 2)" @?= showsPrec 11 (p' 1 2) ""+ ]++ , testGroup "Show1"+ [ testCase "show1" $ "MyCompose (Just [()])" @?= show (MyCompose (Just [()])) ] , testGroup "Meta"