-- 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: -- --
-- 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 a signature for an algebraic class. For exaple: -- --
-- deriveSignature ''Num ---- -- deriveSignature creates the signature data type and an instance -- for it of the AlgebraSignature class. DeriveFunctor is -- used the generate the Functor 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] -> SignatureTH signatureName :: SignatureTH -> Name typeVarName :: SignatureTH -> Name operations :: SignatureTH -> [OperationTH] data OperationTH OperationTH :: Name -> Name -> [Type] -> OperationTH functionName :: OperationTH -> Name operationName :: OperationTH -> Name arguments :: OperationTH -> [Type] getSignatureInfo :: Name -> Q SignatureTH buildSignatureDataType :: SignatureTH -> [Dec] signatureInstance :: Name -> SignatureTH -> [Dec] module Data.Algebra class Traversable f => AlgebraSignature f where type family Class f :: * -> Constraint evaluate :: (AlgebraSignature f, Class f b) => f b -> b class Algebra f a algebra :: (Algebra f a, AlgebraSignature f) => f a -> a -- | 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 a signature for an algebraic class. For exaple: -- --
-- deriveSignature ''Num ---- -- deriveSignature creates the signature data type and an instance -- for it of the AlgebraSignature class. DeriveFunctor is -- used the generate the Functor instance of the signature. -- -- This will do nothing if there is already a signature for the class in -- scope. deriveSignature :: Name -> Q [Dec] -- | The Monoid signature has this AlgebraSignature instance: -- --
-- 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 --data MonoidSignature a Op_mempty :: MonoidSignature a Op_mappend :: a -> a -> MonoidSignature a Op_mconcat :: [a] -> MonoidSignature a instance Functor MonoidSignature instance Foldable MonoidSignature instance Traversable MonoidSignature instance Show a => Show (MonoidSignature a) instance AlgebraSignature MonoidSignature instance (Class f b) => Algebra f (a -> b) instance (Class f m, Class f n) => Algebra f (m, n) instance Algebra f ()