packages feed

syb-with-class 0.6.1.10 → 0.6.1.11

raw patch · 6 files changed

+101/−43 lines, 6 filesdep +HUnitdep +syb-with-classdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: HUnit, syb-with-class

Dependency ranges changed: base

API changes (from Hackage documentation)

- Data.Generics.SYB.WithClass.Instances: instance (Data.Generics.SYB.WithClass.Context.Sat (ctx (GHC.Base.Maybe a)), Data.Generics.SYB.WithClass.Basics.Data ctx a) => Data.Generics.SYB.WithClass.Basics.Data ctx (GHC.Base.Maybe a)
+ Data.Generics.SYB.WithClass.Basics: infix 4 :~~:
+ Data.Generics.SYB.WithClass.Instances: instance (Data.Generics.SYB.WithClass.Context.Sat (ctx (GHC.Maybe.Maybe a)), Data.Generics.SYB.WithClass.Basics.Data ctx a) => Data.Generics.SYB.WithClass.Basics.Data ctx (GHC.Maybe.Maybe a)
- Data.Generics.SYB.WithClass.Basics: Qr :: r -> r -> Qr r a
+ Data.Generics.SYB.WithClass.Basics: Qr :: (r -> r) -> Qr r a
- Data.Generics.SYB.WithClass.Basics: [HRefl] :: a :~~: a
+ Data.Generics.SYB.WithClass.Basics: [HRefl] :: forall k1 k2 (a :: k1) (b :: k2). () => a :~~: a
- Data.Generics.SYB.WithClass.Basics: [Refl] :: a :~: a
+ Data.Generics.SYB.WithClass.Basics: [Refl] :: forall k (a :: k) (b :: k). () => a :~: a
- Data.Generics.SYB.WithClass.Basics: data (:~:) (a :: k) (b :: k) :: forall k. () => k -> k -> *
+ Data.Generics.SYB.WithClass.Basics: data (:~:) (a :: k) (b :: k) :: forall k. () => k -> k -> Type
- Data.Generics.SYB.WithClass.Basics: data (:~~:) (a :: k1) (b :: k2) :: forall k1 k2. () => k1 -> k2 -> *
+ Data.Generics.SYB.WithClass.Basics: data (:~~:) (a :: k1) (b :: k2) :: forall k1 k2. () => k1 -> k2 -> Type
- Data.Generics.SYB.WithClass.Basics: eqT :: (Typeable a, Typeable b) => Maybe a :~: b
+ Data.Generics.SYB.WithClass.Basics: eqT :: (Typeable a, Typeable b) => Maybe (a :~: b)
- Data.Generics.SYB.WithClass.Basics: gcast :: (Typeable a, Typeable b) => c a -> Maybe c b
+ Data.Generics.SYB.WithClass.Basics: gcast :: (Typeable a, Typeable b) => c a -> Maybe (c b)
- Data.Generics.SYB.WithClass.Basics: gcast1 :: (Typeable t, Typeable t') => c t a -> Maybe c t' a
+ Data.Generics.SYB.WithClass.Basics: gcast1 :: (Typeable t, Typeable t') => c (t a) -> Maybe (c (t' a))
- Data.Generics.SYB.WithClass.Basics: gcast2 :: (Typeable t, Typeable t') => c t a b -> Maybe c t' a b
+ Data.Generics.SYB.WithClass.Basics: gcast2 :: (Typeable t, Typeable t') => c (t a b) -> Maybe (c (t' a b))

Files

Data/Generics/SYB/WithClass/Basics.hs view
@@ -1,7 +1,7 @@-{-# LANGUAGE UndecidableInstances, OverlappingInstances, Rank2Types,+{-# LANGUAGE UndecidableInstances, Rank2Types,     CPP, KindSignatures, MultiParamTypeClasses, EmptyDataDecls #-} -{-+{- |  (C) 2004--2005 Ralf Laemmel, Simon D. Foster @@ -33,7 +33,7 @@ #endif  --------------------------------------------------------------------------------- The ingenious Data class+-- * The ingenious Data class  class (Typeable a, Sat (ctx a)) => Data ctx a @@ -91,12 +91,12 @@  ------------------------------------------------------------------------------ --- Generic transformations+-- * Generic transformations  type GenericT ctx = forall a. Data ctx a => a -> a  --- Generic map for transformations+-- | Generic map for transformations  gmapT :: Proxy ctx -> GenericT ctx -> GenericT ctx @@ -105,18 +105,18 @@     k (ID g) y = ID (g (f y))  --- The identity type constructor+-- | The identity type constructor  newtype ID x = ID { unID :: x }   ------------------------------------------------------------------------------ --- Generic monadic transformations+-- | Generic monadic transformations  type GenericM m ctx = forall a. Data ctx a => a -> m a --- Generic map for monadic transformations+-- | Generic map for monadic transformations  gmapM :: Monad m => Proxy ctx -> GenericM m ctx -> GenericM m ctx gmapM ctx f = gfoldl ctx k return@@ -127,12 +127,12 @@  ------------------------------------------------------------------------------ --- Generic queries+-- * Generic queries  type GenericQ ctx r = forall a. Data ctx a => a -> r  --- Map for queries+-- | Map for queries  gmapQ :: Proxy ctx -> GenericQ ctx r -> GenericQ ctx [r] gmapQ ctx f = gmapQr ctx (:) [] f@@ -148,14 +148,14 @@   where     k (Qr g) y = Qr (\s -> g (f y `o` s)) --- The type constructor used in definition of gmapQr+-- | The type constructor used in definition of gmapQr newtype Qr r a = Qr { unQr  :: r -> r }    ------------------------------------------------------------------------------ ----- Generic unfolding+-- * Generic unfolding -- ------------------------------------------------------------------------------ @@ -193,15 +193,15 @@  ------------------------------------------------------------------------------ ----- Datatype and constructor representations+-- * Datatype and constructor representations -- ------------------------------------------------------------------------------   -- -- | Representation of datatypes.--- | A package of constructor representations with names of type and module.--- | The list of constructors could be an array, a balanced tree, or others.+--   A package of constructor representations with names of type and module.+--   The list of constructors could be an array, a balanced tree, or others. -- data DataType = DataType                         { tycon   :: String@@ -264,7 +264,7 @@  ------------------------------------------------------------------------------ ----- Observers for datatype representations+-- * Observers for datatype representations -- ------------------------------------------------------------------------------ @@ -304,7 +304,7 @@  ------------------------------------------------------------------------------ ----- Representations of algebraic data types+-- * Representations of algebraic data types -- ------------------------------------------------------------------------------ @@ -352,7 +352,7 @@  ------------------------------------------------------------------------------ ----- From strings to constr's and vice versa: all data types+-- * From strings to constr's and vice versa: all data types -- ------------------------------------------------------------------------------ @@ -389,7 +389,7 @@  ------------------------------------------------------------------------------ ----- Convenience funtions: algebraic data types+-- * Convenience funtions: algebraic data types -- ------------------------------------------------------------------------------ @@ -425,7 +425,7 @@  ------------------------------------------------------------------------------ ----- Representation of primitive types+-- * Representation of primitive types -- ------------------------------------------------------------------------------ @@ -453,7 +453,7 @@                         }  --- Makes a constructor for primitive types+-- | Makes a constructor for primitive types mkPrimCon :: DataType -> String -> ConstrRep -> Constr mkPrimCon dt str cr = Constr                         { datatype  = dt@@ -464,18 +464,21 @@                         }  +-- | Makes a constructor for an Int mkIntConstr :: DataType -> Integer -> Constr mkIntConstr dt i = case datarep dt of                   IntRep -> mkPrimCon dt (show i) (IntConstr i)                   _ -> error "mkIntConstr"  +-- | Makes a constructor for a Float mkFloatConstr :: DataType -> Double -> Constr mkFloatConstr dt f = case datarep dt of                     FloatRep -> mkPrimCon dt (show f) (FloatConstr f)                     _ -> error "mkFloatConstr"  +-- | Makes a constructor for a String mkStringConstr :: DataType -> String -> Constr mkStringConstr dt str = case datarep dt of                        StringRep -> mkPrimCon dt str (StringConstr str)@@ -484,7 +487,7 @@  ------------------------------------------------------------------------------ ----- Non-representations for non-presentable types+-- * Non-representations for non-presentable types -- ------------------------------------------------------------------------------ 
Data/Generics/SYB/WithClass/Context.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE UndecidableInstances, OverlappingInstances, EmptyDataDecls #-}+{-# LANGUAGE UndecidableInstances, EmptyDataDecls #-} -{-+{- |  (C) 2004 Ralf Laemmel @@ -16,7 +16,7 @@ ------------------------------------------------------------------------------  ----- The Sat class from John Hughes' "Restricted Data Types in Haskell"+-- | The Sat class from John Hughes' "Restricted Data Types in Haskell" --  class Sat a@@ -26,7 +26,7 @@  ------------------------------------------------------------------------------ --- No context+-- | No context  data NoCtx a @@ -38,7 +38,7 @@  ------------------------------------------------------------------------------ --- Pair context+-- | Pair context  data PairCtx l r a    = PairCtx { leftCtx  :: l a
Data/Generics/SYB/WithClass/Derive.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE TemplateHaskell, CPP #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-}--- We can't warn about missing sigs as we have a group of decls in+-- | We can't warn about missing sigs as we have a group of decls in -- quasi-quotes that we're going to put in a class instance  --@@ -236,11 +236,15 @@              |] #endif -{- instance Data NameSet where+{- |+   @@+   instance Data NameSet where    gunfold _ _ _ = error ("gunfold not implemented")    toConstr x = error ("toConstr not implemented for " ++ show (typeOf x))    dataTypeOf x = error ("dataTypeOf not implemented for " ++ show (typeOf x))-   gfoldl f z x = z x -}+   gfoldl f z x = z x+   @@+-}  typeInfo :: Dec          -> Q (Name,            -- Name of the datatype
Data/Generics/SYB/WithClass/Instances.hs view
@@ -1,6 +1,12 @@+------------------------------------------------------------------------------+--+-- | Instances of the Data class for Prelude-like types.+-- We define top-level definitions for representations.+--+------------------------------------------------------------------------------+ {-# LANGUAGE TemplateHaskell, FlexibleInstances,-             UndecidableInstances, OverlappingInstances, CPP,-             MultiParamTypeClasses #-}+             UndecidableInstances, CPP, MultiParamTypeClasses #-} #if MIN_VERSION_base(4,7,0) {-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-} #endif@@ -27,13 +33,6 @@ import Control.Concurrent.MVar   -- So we can give Data instance for MVar & Co. import qualified Data.Map as M import qualified Data.Set as S-------------------------------------------------------------------------------------- Instances of the Data class for Prelude-like types.--- We define top-level definitions for representations.----------------------------------------------------------------------------------   falseConstr :: Constr
syb-with-class.cabal view
@@ -1,5 +1,5 @@ Name:               syb-with-class-Version:            0.6.1.10+Version:            0.6.1.11 License:            BSD3 License-file:       LICENSE Copyright:          2004 - 2008 The University of Glasgow, CWI,@@ -15,15 +15,16 @@     Classes, and Template Haskell code to generate instances, for the     Scrap Your Boilerplate With Class system. Category:           Data-Tested-With:        GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC==8.0.1, GHC==8.2.1, GHC==8.4.3, GHC==8.6.1+Tested-With:        GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC==8.0.1, GHC==8.2.1, GHC==8.4.3, GHC==8.6.3 Build-Type:         Simple-Cabal-Version:      >= 1.6+Cabal-Version:      >= 1.10  source-repository head   type:     git   location: https://github.com/Happstack/syb-with-class  Library+    Default-Language: Haskell2010     Build-Depends:      base >= 3 && < 5, template-haskell >= 2.4 && < 2.15, bytestring, array, containers     Exposed-modules:         Data.Generics.SYB.WithClass.Basics@@ -31,8 +32,17 @@         Data.Generics.SYB.WithClass.Derive         Data.Generics.SYB.WithClass.Instances -    Extensions: UndecidableInstances, OverlappingInstances, Rank2Types,+    Default-Extensions: UndecidableInstances, OverlappingInstances, Rank2Types,             EmptyDataDecls, TemplateHaskell, FlexibleInstances, CPP,             KindSignatures, MultiParamTypeClasses      GHC-Options: -Wall++test-suite syb-with-class-test+    Default-Language: Haskell2010+    Type: exitcode-stdio-1.0+    Hs-Source-Dirs: tests+    GHC-Options: -Wall+    Main-Is: Test.hs+    Build-Depends: base, HUnit, syb-with-class+    Default-Extensions: OverlappingInstances
+ tests/Test.hs view
@@ -0,0 +1,42 @@+-- Minimal demonstration of syb-with-class.  Here we have a class Size+-- with a base instance.  Then we override it for lists, and+-- demonstrate how gsize uses the list behavior on lists and the base+-- behavior otherwise.++{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS -Wall #-}++import Data.Generics.SYB.WithClass.Basics (Data, gmapQ, Proxy)+import Data.Generics.SYB.WithClass.Context (Sat(dict))+import Data.Generics.SYB.WithClass.Instances ()+import Test.HUnit (assertEqual, Counts(..), runTestTT, showCounts, Test(TestCase))++class Size a where+    gsize :: a -> Int++-- Dictionary type and Sat instance+data SizeD a = SizeD { gsizeD :: a -> Int }++instance Size t => Sat (SizeD t) where+  dict = SizeD { gsizeD = gsize }++instance {-# OVERLAPPABLE #-} Data SizeD t => Size t where+  -- The base behavior of gsize for any instance of Data+  gsize t = 1 + sum (gmapQ (error "urk" :: Proxy SizeD) (gsizeD dict) t)++instance Size a => Size [a] where+  -- Override base gsize behavior for lists+  gsize [] = 0+  gsize (x:xs) = gsize x + gsize xs++main :: IO ()+main = do+  counts <- runTestTT (let expected = (2,1)+                           actual = (gsize ['a', 'b'], gsize 'x') in+                       TestCase (assertEqual "sample" expected actual))+  case counts of+    Counts {errors = 0, failures = 0} -> return ()+    _ -> error (showCounts counts)