-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A product-of-sums generics library -- -- A generics library that represents a non-recursive Haskell 98 datatype -- as a product-of-sums. Each type is represented with a single tag, and -- a product of sums of fields. The tag represents all constructor -- choices in the type, the fields contain all the values in the type. -- This representation maps easily to a struct of unions, which is a -- memory-efficient way to store sum datatypes. @package posable @version 1.0.0.0 -- | This module exports the Product and Sum type, and type- -- and valuelevel functions on these types. module Generics.POSable.Representation -- | Concatenation of typelevel lists type family (++) (xs :: [k]) (ys :: [k]) :: [k] infixr 5 ++ -- | Type witness for Product data ProductType :: [[Type]] -> Type [PTNil] :: ProductType '[] [PTCons] :: SumType x -> ProductType xs -> ProductType (x : xs) -- | Concatenates ProductType values concatPT :: ProductType x -> ProductType y -> ProductType (x ++ y) -- | Typelevel product of Sums with values data Product :: [[Type]] -> Type [Nil] :: Product '[] [Cons] :: Sum x -> Product xs -> Product (x : xs) -- | Concatenates Product values concatP :: Product x -> Product y -> Product (x ++ y) -- | Type witness for Sum data SumType :: [Type] -> Type [STSucc] :: Ground x => x -> SumType xs -> SumType (x : xs) [STZero] :: SumType '[] -- | Typelevel sum, contains one value from the typelevel list of types, or -- undefined. data Sum :: [Type] -> Type [Pick] :: Ground x => x -> Sum (x : xs) [Skip] :: Ground x => Sum xs -> Sum (x : xs) -- | Zip two lists of lists with ++` as operator, while keeping the length -- of the longest outer list -- -- Example: -- --
-- >>> :kind! Merge '[ '[A, B, C], '[D, E]] '[ '[F, G]] -- Merge '[ '[A, B, C], '[D, E]] '[ '[F, G]] :: [[Type]] -- = '[ '[A, B, C, F, G], '[D, E]] --type family Merge (xs :: [[Type]]) (ys :: [[Type]]) :: [[Type]] -- | Fold Merge over a list (of lists, of lists) -- -- Example: -- --
-- >>> :kind! FoldMerge '[ '[ '[A, B, C], '[D, E]], '[ '[F, G]], '[ '[H]]] -- FoldMerge '[ '[ '[A, B, C], '[D, E]], '[ '[F, G]], '[ '[H]]] :: [[Type]] -- = '[ '[A, B, C, F, G, H], '[D, E]] --type family FoldMerge (xss :: [[[Type]]]) :: [[Type]] -- | Map Concat over a list (of lists, of lists), typelevel -- equivalent of -- --
-- map . concat :: [[[a]]] -> [[a]] ---- -- Example: -- --
-- >>> :kind! MapConcat '[ '[ '[A, B], '[C, D]], '[[E, F], '[G, H]]] -- MapConcat '[ '[ '[A, B], '[C, D]], '[[E, F], '[G, H]]] :: [[Type]] -- = '[ '[A, B, C, D], '[E, F, G, H]] --type family MapConcat (xsss :: [[[x]]]) :: [[x]] -- | Concatenate a list of lists, typelevel equivalent of -- --
-- concat :: [[a]] -> [a]` ---- -- Example: -- --
-- >>> :kind! Concat '[ '[A, B], '[C, D]] -- Concat '[ '[A, B], '[C, D]] :: [Type] -- = '[A, B, C, D] --type family Concat (xss :: [[x]]) :: [x] -- | The set of types that can exist in the sums. This set can be extended -- by the user by providing an instance of Ground for their types. The -- mkGround function gives a default value for the type. Ground depends -- on Typeable, as this makes it possible for library users to inspect -- the types of the contents of the sums. class (Typeable a) => Ground a mkGround :: Ground a => a -- | Merge two ProductTypes mergeT :: ProductType l -> ProductType r -> ProductType (Merge l r) -- | Merge a ProductType and a Product merge :: Either (Product l, ProductType r) (ProductType l, Product r) -> Product (Merge l r) -- | UnMerge a Product, using two ProductTypes as witnesses -- for the left and right argument of Merge. Produces a value of -- type Product left splitLeft :: Product (Merge l r) -> ProductType l -> ProductType r -> Product l -- | UnMerge a Product, using two ProductTypes as witnesses -- for the left and right argument of Merge. Produces a value of -- type Product right splitRight :: Product (Merge l r) -> ProductType l -> ProductType r -> Product r -- | UnConcat a Product, using a ProductType as the witness -- for the first argument of ++. Produces a tuple with the first -- and second argument of ++ unConcatP :: Product (x ++ y) -> ProductType x -> (Product x, Product y) data Undef Undef :: Undef instance Generics.SOP.Universe.Generic Generics.POSable.Representation.Undef instance GHC.Generics.Generic Generics.POSable.Representation.Undef instance GHC.Show.Show Generics.POSable.Representation.Undef instance GHC.Classes.Eq Generics.POSable.Representation.Undef instance Data.SOP.Constraint.All2 GHC.Classes.Eq xs => GHC.Classes.Eq (Generics.POSable.Representation.Product xs) instance Data.SOP.Constraint.All GHC.Classes.Eq xs => GHC.Classes.Eq (Generics.POSable.Representation.Sum xs) instance Data.SOP.Constraint.All2 GHC.Show.Show (Generics.POSable.Representation.Map2TypeRep xs) => GHC.Show.Show (Generics.POSable.Representation.ProductType xs) instance Data.SOP.Constraint.All GHC.Show.Show (Generics.POSable.Representation.MapTypeRep xs) => GHC.Show.Show (Generics.POSable.Representation.SumType xs) instance Generics.POSable.Representation.Ground Generics.POSable.Representation.Undef instance Data.SOP.Constraint.All2 GHC.Show.Show xs => GHC.Show.Show (Generics.POSable.Representation.Product xs) instance Data.SOP.Constraint.All GHC.Show.Show x => GHC.Show.Show (Generics.POSable.Representation.Sum x) -- | Exports the POSable class, which has a generic implementation -- GPOSable. Also re-exports Generic.SOP, which is needed to -- derive POSable. module Generics.POSable.POSable -- | POSable, the base of this library. Provide a compact memory -- representation for a type and a function to get back to the original -- type. This memory representation consist of choices, that -- represent all constructor choices in the type in a single Finite -- integer, and fields which represents all values in the type as -- a Product of Sums, which can be mapped to a struct-of-arrays -- representation for use in array-based languages like Accelerate. class (KnownNat (Choices x)) => POSable x where { type family Choices x :: Nat; type family Fields x :: [[Type]]; type Choices x = GChoices (SOP I (Code x)); type Fields x = GFields (SOP I (Code x)); } choices :: POSable x => x -> Finite (Choices x) choices :: (POSable x, Generic x, GPOSable (SOP I (Code x)), GChoices (SOP I (Code x)) ~ Choices x) => x -> Finite (Choices x) -- | The tags function returns the range of each constructor. A few -- examples: >>> tags Bool [1,1] >>> tags -- (Either Float Float) [1,1] >>> tags (Bool, Bool) [4] -- >>> tags (Either Bool Bool) [2,2] tags :: POSable x => [Integer] -- | The tags function returns the range of each constructor. A few -- examples: >>> tags Bool [1,1] >>> tags -- (Either Float Float) [1,1] >>> tags (Bool, Bool) [4] -- >>> tags (Either Bool Bool) [2,2] tags :: (POSable x, GPOSable (SOP I (Code x))) => [Integer] fromPOSable :: POSable x => Finite (Choices x) -> Product (Fields x) -> x fromPOSable :: (POSable x, Generic x, GPOSable (SOP I (Code x)), Fields x ~ GFields (SOP I (Code x)), Choices x ~ GChoices (SOP I (Code x))) => Finite (Choices x) -> Product (Fields x) -> x fields :: POSable x => x -> Product (Fields x) fields :: (POSable x, Generic x, Fields x ~ GFields (SOP I (Code x)), GPOSable (SOP I (Code x))) => x -> Product (Fields x) emptyFields :: POSable x => ProductType (Fields x) emptyFields :: (POSable x, GPOSable (SOP I (Code x)), Fields x ~ GFields (SOP I (Code x))) => ProductType (Fields x) -- | The class of representable datatypes. -- -- The SOP approach to generic programming is based on viewing datatypes -- as a representation (Rep) built from the sum of products of its -- components. The components of a datatype are specified using the -- Code type family. -- -- The isomorphism between the original Haskell datatype and its -- representation is witnessed by the methods of this class, from -- and to. So for instances of this class, the following laws -- should (in general) hold: -- --
-- to . from === id :: a -> a -- from . to === id :: Rep a -> Rep a ---- -- You typically don't define instances of this class by hand, but rather -- derive the class instance automatically. -- -- Option 1: Derive via the built-in GHC-generics. For this, you -- need to use the DeriveGeneric extension to first derive an -- instance of the Generic class from module GHC.Generics. -- With this, you can then give an empty instance for Generic, and -- the default definitions will just work. The pattern looks as follows: -- --
-- import qualified GHC.Generics as GHC -- import Generics.SOP -- -- ... -- -- data T = ... deriving (GHC.Generic, ...) -- -- instance Generic T -- empty -- instance HasDatatypeInfo T -- empty, if you want/need metadata ---- -- Option 2: Derive via Template Haskell. For this, you need to -- enable the TemplateHaskell extension. You can then use -- deriveGeneric from module Generics.SOP.TH to have the -- instance generated for you. The pattern looks as follows: -- --
-- import Generics.SOP -- import Generics.SOP.TH -- -- ... -- -- data T = ... -- -- deriveGeneric ''T -- derives HasDatatypeInfo as well ---- -- Tradeoffs: Whether to use Option 1 or 2 is mainly a matter of -- personal taste. The version based on Template Haskell probably has -- less run-time overhead. -- -- Non-standard instances: It is possible to give Generic -- instances manually that deviate from the standard scheme, as long as -- at least -- --
-- to . from === id :: a -> a ---- -- still holds. class All SListI :: [Type] -> Constraint Code a => Generic a -- | Finite number type. Finite n is inhabited by exactly -- n values. Invariants: -- --
-- getFinite x < natVal x ---- --
-- getFinite x >= 0 --data Finite (n :: Nat) instance (Data.SOP.Constraint.All2 Generics.POSable.POSable.POSable xss, GHC.TypeNats.KnownNat (Generics.POSable.POSable.Sums (Generics.POSable.POSable.MapProducts (Generics.POSable.POSable.Map2Choices xss))), Data.SOP.Constraint.All2 GHC.TypeNats.KnownNat (Generics.POSable.POSable.Map2Choices xss), Data.SOP.Constraint.All GHC.TypeNats.KnownNat (Generics.POSable.POSable.MapProducts (Generics.POSable.POSable.Map2Choices xss)), GHC.TypeNats.KnownNat (Generics.POSable.POSable.Length xss)) => Generics.POSable.POSable.GPOSable (Data.SOP.NS.SOP Data.SOP.BasicFunctors.I xss) -- | This module contains instances of POSable for all Haskell -- prelude data types as well as fixed size integers from Data.Int -- (Int8, Int16, Int32 and Int64) module Generics.POSable.Instances -- | POSable, the base of this library. Provide a compact memory -- representation for a type and a function to get back to the original -- type. This memory representation consist of choices, that -- represent all constructor choices in the type in a single Finite -- integer, and fields which represents all values in the type as -- a Product of Sums, which can be mapped to a struct-of-arrays -- representation for use in array-based languages like Accelerate. class (KnownNat (Choices x)) => POSable x instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1) => Generics.POSable.POSable.POSable (x0, x1) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2) => Generics.POSable.POSable.POSable (x0, x1, x2) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3) => Generics.POSable.POSable.POSable (x0, x1, x2, x3) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9, Generics.POSable.POSable.POSable x10) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9, Generics.POSable.POSable.POSable x10, Generics.POSable.POSable.POSable x11) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9, Generics.POSable.POSable.POSable x10, Generics.POSable.POSable.POSable x11, Generics.POSable.POSable.POSable x12) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9, Generics.POSable.POSable.POSable x10, Generics.POSable.POSable.POSable x11, Generics.POSable.POSable.POSable x12, Generics.POSable.POSable.POSable x13) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9, Generics.POSable.POSable.POSable x10, Generics.POSable.POSable.POSable x11, Generics.POSable.POSable.POSable x12, Generics.POSable.POSable.POSable x13, Generics.POSable.POSable.POSable x14) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14) instance (Generics.POSable.POSable.POSable x0, Generics.POSable.POSable.POSable x1, Generics.POSable.POSable.POSable x2, Generics.POSable.POSable.POSable x3, Generics.POSable.POSable.POSable x4, Generics.POSable.POSable.POSable x5, Generics.POSable.POSable.POSable x6, Generics.POSable.POSable.POSable x7, Generics.POSable.POSable.POSable x8, Generics.POSable.POSable.POSable x9, Generics.POSable.POSable.POSable x10, Generics.POSable.POSable.POSable x11, Generics.POSable.POSable.POSable x12, Generics.POSable.POSable.POSable x13, Generics.POSable.POSable.POSable x14, Generics.POSable.POSable.POSable x15) => Generics.POSable.POSable.POSable (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15) instance Generics.POSable.POSable.POSable GHC.Types.Bool instance Generics.POSable.POSable.POSable x => Generics.POSable.POSable.POSable (GHC.Maybe.Maybe x) instance (Generics.POSable.POSable.POSable l, Generics.POSable.POSable.POSable r) => Generics.POSable.POSable.POSable (Data.Either.Either l r) instance Generics.POSable.POSable.POSable GHC.Types.Ordering instance Generics.POSable.POSable.POSable () instance Generics.POSable.POSable.POSable Generics.POSable.Representation.Undef module Generics.POSable.TH mkPOSableGround :: Name -> DecsQ