-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Conversions between algebraic classes and F-algebras. -- -- Algebraic classes are type classes where all the methods return a -- value of the same type, which is also the class parameter. Examples -- from base are Num and Monoid. -- -- F-algebras are functions f a -> a, where the functor -- f is called the signature, and the type a the -- carrier. -- -- This package relates these 2 concepts, and can create conversions -- between the two using Template Haskell. More specifically, it can -- generate: -- -- -- -- This is useful because type classes are more commonly used in Haskell -- than F-algebras, but F-algebras are easier to work with, because they -- are just functions. @package algebraic-classes @version 0.9 module Data.Algebra.Internal -- | The signature datatype for the class c. class Traversable f => AlgebraSignature f where { type family Class f :: * -> Constraint; } -- | Translate the operations of the signature to method calls of the -- class. evaluate :: (AlgebraSignature f, Class f b) => f b -> b class Algebra f a -- | An algebra f a -> a corresponds to an instance of -- a of the class Class f. In some cases, for example -- for tuple types, you can give an algebra generically for every -- signature: -- --
--   instance (Class f m, Class f n) => Algebra f (m, n) where
--     algebra fmn = (evaluate (fmap fst fmn), evaluate (fmap snd fmn))
--   
algebra :: (Algebra f a, AlgebraSignature f) => f a -> a -- | If you just want to applicatively lift existing instances, you can use -- this default implementation of algebra. algebraA :: (Applicative g, Class f b, AlgebraSignature f) => f (g b) -> g b instance Data.Algebra.Internal.Algebra f () instance (Data.Algebra.Internal.Class f m, Data.Algebra.Internal.Class f n) => Data.Algebra.Internal.Algebra f (m, n) instance Data.Algebra.Internal.Class f b => Data.Algebra.Internal.Algebra f (a -> b) instance Data.Algebra.Internal.Class f b => Data.Algebra.Internal.Algebra f (GHC.Types.IO b) instance Data.Algebra.Internal.Class f b => Data.Algebra.Internal.Algebra f (GHC.Base.Maybe b) instance Data.Algebra.Internal.Class f b => Data.Algebra.Internal.Algebra f (Data.Either.Either a b) instance Data.Algebra.Internal.Class f b => Data.Algebra.Internal.Algebra f (GHC.Conc.Sync.STM b) instance (GHC.Base.Monoid m, Data.Algebra.Internal.Class f b) => Data.Algebra.Internal.Algebra f (Data.Functor.Const.Const m b) module Data.Algebra.TH -- | Derive an instance for an algebraic class. For example: -- --
--   deriveInstance [t| (Num m, Num n) => Num (m, n) |]
--   
-- -- To be able to derive an instance for a of class c, -- we need an instance of Algebra f a, where f -- is the signature of c. -- -- deriveInstance will generate a signature for the class if there -- is no signature in scope. deriveInstance :: Q Type -> Q [Dec] -- | Derive an instance for an algebraic class with a given partial -- implementation. For example: -- --
--   deriveInstanceWith [t| Num n => Num (Integer -> n) |]
--     [d|
--       fromInteger x y = fromInteger (x + y)
--     |]
--   
deriveInstanceWith :: Q Type -> Q [Dec] -> Q [Dec] -- | Derive an instance for an algebraic class with a given partial -- implementation, but don't generate the signature. This is for when you -- want to derive several instances of the same class, but can't splice -- the results directly. In that case deriveSignature can't detect -- it has already generated the signature earlier. deriveInstanceWith_skipSignature :: Q Type -> Q [Dec] -> Q [Dec] -- | Derive the instances for the superclasses too, all using the same -- context. Usually you'd want to do this manually since you can often -- give a stricter context, for example: -- --
--   deriveSuperclassInstances [t| (Fractional m, Fractional n) => Fractional (m, n) |]
--   
-- -- will derive an instance (Fractional m, Fractional n) => Num (m, -- n) while the instance only needs (Num m, Num n). deriveSuperclassInstances :: Q Type -> Q [Dec] -- | Derive a signature for an algebraic class. For example: -- --
--   deriveSignature ''Monoid
--   
-- -- The above would generate the following: -- --
--   data MonoidSignature a = Op_mempty | Op_mappend a a | Op_mconcat [a]
--     deriving (Functor, Foldable, Traversable, Eq, Ord)
--   
--   type instance Signature Monoid = MonoidSignature
--   
--   instance AlgebraSignature MonoidSignature where
--     type Class MonoidSignature = Monoid
--     evaluate Op_mempty = mempty
--     evaluate (Op_mappend a b) = mappend a b
--     evaluate (Op_mconcat ms) = mconcat ms
--   
--   instance Show a => Show (MonoidSignature a) where
--     showsPrec d Op_mempty          = showParen (d > 10) $ showString "mempty"
--     showsPrec d (Op_mappend a1 a2) = showParen (d > 10) $ showString "mappend" . showChar ' ' . showsPrec 11 a1 . showChar ' ' . showsPrec 11 a2
--     showsPrec d (Op_mconcat a1)    = showParen (d > 10) $ showString "mconcat" . showChar ' ' . showsPrec 11 a1
--   
-- -- deriveSignature creates the signature data type and an instance -- for it of the AlgebraSignature class. -- DeriveTraversable is used the generate the Traversable -- instance of the signature. -- -- This will do nothing if there is already a signature for the class in -- scope. deriveSignature :: Name -> Q [Dec] data SignatureTH SignatureTH :: Name -> Name -> [OperationTH] -> [SuperclassTH] -> SignatureTH [signatureName] :: SignatureTH -> Name [typeVarName] :: SignatureTH -> Name [operations] :: SignatureTH -> [OperationTH] [superclasses] :: SignatureTH -> [SuperclassTH] data OperationTH OperationTH :: Name -> Name -> Int -> Con -> Fixity -> OperationTH [functionName] :: OperationTH -> Name [operationName] :: OperationTH -> Name [arity] :: OperationTH -> Int [constructor] :: OperationTH -> Con [fixity] :: OperationTH -> Fixity data SuperclassTH SuperclassTH :: Name -> Name -> SignatureTH -> SuperclassTH [superclassName] :: SuperclassTH -> Name [constrName] :: SuperclassTH -> Name [signatureTH] :: SuperclassTH -> SignatureTH getSignatureInfo :: Name -> Q SignatureTH buildSignatureDataType :: SignatureTH -> [Dec] signatureInstances :: Name -> SignatureTH -> [Dec] module Data.Algebra -- | Derive an instance for an algebraic class. For example: -- --
--   deriveInstance [t| (Num m, Num n) => Num (m, n) |]
--   
-- -- To be able to derive an instance for a of class c, -- we need an instance of Algebra f a, where f -- is the signature of c. -- -- deriveInstance will generate a signature for the class if there -- is no signature in scope. deriveInstance :: Q Type -> Q [Dec] -- | Derive an instance for an algebraic class with a given partial -- implementation. For example: -- --
--   deriveInstanceWith [t| Num n => Num (Integer -> n) |]
--     [d|
--       fromInteger x y = fromInteger (x + y)
--     |]
--   
deriveInstanceWith :: Q Type -> Q [Dec] -> Q [Dec] class Algebra f a -- | An algebra f a -> a corresponds to an instance of -- a of the class Class f. In some cases, for example -- for tuple types, you can give an algebra generically for every -- signature: -- --
--   instance (Class f m, Class f n) => Algebra f (m, n) where
--     algebra fmn = (evaluate (fmap fst fmn), evaluate (fmap snd fmn))
--   
algebra :: (Algebra f a, AlgebraSignature f) => f a -> a -- | If you just want to applicatively lift existing instances, you can use -- this default implementation of algebra. algebraA :: (Applicative g, Class f b, AlgebraSignature f) => f (g b) -> g b -- | The signature datatype for the class c. class Traversable f => AlgebraSignature f where { type family Class f :: * -> Constraint; } -- | Translate the operations of the signature to method calls of the -- class. evaluate :: (AlgebraSignature f, Class f b) => f b -> b