packages feed

algebraic-classes 0.1 → 0.2

raw patch · 3 files changed

+29/−16 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Algebra: instance (Class f b) => Algebra f (a -> b)
- Data.Algebra: instance (Class f m, Class f n) => Algebra f (m, n)
- Data.Algebra: instance Algebra f ()
+ Data.Algebra: algebraA :: (Applicative g, Class f b, AlgebraSignature f) => f (g b) -> g b
+ Data.Algebra.Internal: algebraA :: (Applicative g, Class f b, AlgebraSignature f) => f (g b) -> g b
+ Data.Algebra.Internal: instance (Class f b) => Algebra f (Either a b)
+ Data.Algebra.Internal: instance (Class f b) => Algebra f (IO b)
+ Data.Algebra.Internal: instance (Class f b) => Algebra f (Maybe b)
+ Data.Algebra.Internal: instance (Class f b) => Algebra f (STM b)
+ Data.Algebra.Internal: instance (Class f b) => Algebra f (a -> b)
+ Data.Algebra.Internal: instance (Monoid m, Class f b) => Algebra f (Const m b)
+ Data.Algebra.Internal: instance Algebra f ()

Files

Data/Algebra.hs view
@@ -2,8 +2,6 @@     TypeFamilies    , ConstraintKinds   , MultiParamTypeClasses-  , FlexibleInstances-  , UndecidableInstances   , TemplateHaskell   , DeriveFunctor   , DeriveFoldable@@ -23,6 +21,7 @@   ( -- * Classes     AlgebraSignature(..)   , Algebra(..)+  , algebraA     -- * Template Haskell functions   , deriveInstance   , deriveSignature@@ -33,20 +32,8 @@ import Data.Algebra.Internal import Data.Algebra.TH -import Control.Arrow ((&&&)) import Data.Monoid-import Data.Foldable-import Data.Traversable --instance Algebra f () where-  algebra = const () --instance (Class f m, Class f n) => Algebra f (m, n) where-  algebra = evaluate . fmap fst &&& evaluate . fmap snd--instance Class f b => Algebra f (a -> b) where-  algebra fab a = evaluate (fmap ($ a) fab)    -- | The `Monoid` signature has this `AlgebraSignature` instance: --
Data/Algebra/Internal.hs view
@@ -2,6 +2,8 @@     TypeFamilies    , ConstraintKinds   , MultiParamTypeClasses+  , FlexibleInstances+  , UndecidableInstances   #-} ----------------------------------------------------------------------------- -- |@@ -16,8 +18,12 @@ module Data.Algebra.Internal where  import GHC.Exts (Constraint)-import Data.Traversable (Traversable)+import Control.Applicative+import Data.Traversable (Traversable(..)) +import GHC.Conc (STM)+import Data.Monoid+ class Traversable f => AlgebraSignature f where   -- | The class for which @f@ is the signature.   type Class f :: * -> Constraint@@ -31,3 +37,22 @@   -- > instance (Class f m, Class f n) => Algebra f (m, n) where   -- >   algebra fmn = (evaluate (fmap fst fmn), evaluate (fmap snd fmn))   algebra :: 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+algebraA = fmap evaluate . sequenceA++instance Algebra f () where+  algebra = const () ++-- There are 2 possible instances for tuples:+-- instance (Class f m, Class f n) => Algebra f (m, n) where+--   algebra = evaluate . fmap fst &&& evaluate . fmap snd+-- instance (Monoid a, Class f b) => Algebra f (a, b) where algebra = algebraA++instance Class f b => Algebra f (a -> b) where algebra = algebraA+instance Class f b => Algebra f (IO b) where algebra = algebraA+instance Class f b => Algebra f (Maybe b) where algebra = algebraA+instance Class f b => Algebra f (Either a b) where algebra = algebraA+instance Class f b => Algebra f (STM b) where algebra = algebraA+instance (Monoid m, Class f b) => Algebra f (Const m b) where algebra = algebraA
algebraic-classes.cabal view
@@ -1,5 +1,5 @@ name:                algebraic-classes-version:             0.1+version:             0.2 synopsis:            Conversions between algebraic classes and F-algebras. description:         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@.@@ -16,6 +16,7 @@                      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. homepage:            https://github.com/sjoerdvisscher/algebraic-classes+bug-reports:         https://github.com/sjoerdvisscher/algebraic-classes/issues license:             BSD3 license-file:        LICENSE author:              Sjoerd Visscher