product-isomorphic 0.0.1.0 → 0.0.2.0
raw patch · 4 files changed
+89/−7 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Functor.ProductIsomorphic.Class: class ProductIsoApplicative f => ProductIsoEmpty f e
+ Data.Functor.ProductIsomorphic.Class: peLeft :: ProductIsoEmpty f e => f (e, a) -> f a
+ Data.Functor.ProductIsomorphic.Class: peLeftR :: ProductIsoEmpty f e => f a -> f (e, a)
+ Data.Functor.ProductIsomorphic.Class: peRight :: ProductIsoEmpty f e => f (a, e) -> f a
+ Data.Functor.ProductIsomorphic.Class: peRightR :: ProductIsoEmpty f e => f a -> f (a, e)
+ Data.Functor.ProductIsomorphic.Class: pureE :: ProductIsoEmpty f e => f e
+ Data.Functor.ProductIsomorphic.Instances: instance GHC.Base.Alternative f => Data.Functor.ProductIsomorphic.Class.ProductIsoEmpty (Data.Functor.ProductIsomorphic.Instances.WrappedAlter f a) ()
+ Data.Functor.ProductIsomorphic.Instances: instance GHC.Base.Applicative f => Data.Functor.ProductIsomorphic.Class.ProductIsoEmpty (Data.Functor.ProductIsomorphic.Instances.WrappedFunctor f) ()
+ Data.Functor.ProductIsomorphic.Instances: instance GHC.Base.Monoid a => Data.Functor.ProductIsomorphic.Class.ProductIsoEmpty (Data.Functor.Const.Const a) ()
+ Data.Functor.ProductIsomorphic.TupleInstances: instance Data.Functor.ProductIsomorphic.Unsafe.ProductConstructor ()
Files
- product-isomorphic.cabal +7/−1
- src/Data/Functor/ProductIsomorphic/Class.hs +52/−5
- src/Data/Functor/ProductIsomorphic/Instances.hs +26/−1
- src/Data/Functor/ProductIsomorphic/TupleInstances.hs +4/−0
product-isomorphic.cabal view
@@ -1,5 +1,5 @@ name: product-isomorphic-version: 0.0.1.0+version: 0.0.2.0 synopsis: Weaken applicative functor on products description: Weaken applicative functor which allows only product construction. Product constructions and deconstructions@@ -14,6 +14,12 @@ build-type: Simple -- extra-source-files: cabal-version: >=1.10+tested-with: GHC == 8.2.1+ , GHC == 8.0.1, GHC == 8.0.2+ , GHC == 7.10.1, GHC == 7.10.2, GHC == 7.10.3+ , GHC == 7.8.1, GHC == 7.8.2, GHC == 7.8.3, GHC == 7.8.4+ , GHC == 7.6.1, GHC == 7.6.2, GHC == 7.6.3+ , GHC == 7.4.1, GHC == 7.4.2 library exposed-modules:
src/Data/Functor/ProductIsomorphic/Class.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-} -- | -- Module : Data.Functor.ProductIsomorphic.Class@@ -11,13 +12,21 @@ -- -- This module defines functor interfaces which morphed functions -- are restricted to products.-module Data.Functor.ProductIsomorphic.Class- ( ProductIsoFunctor (..)- , ProductIsoApplicative (..)- , ProductIsoAlternative (..)- ) where+module Data.Functor.ProductIsomorphic.Class (+ -- * ProductIso classes+ ProductIsoFunctor (..),+ ProductIsoApplicative (..),+ ProductIsoAlternative (..), + -- * Empty element+ ProductIsoEmpty (..),+ peRightR, peLeftR,++ --- (<|), (|>),+ ) where+ import Data.Functor.ProductIsomorphic.Unsafe (ProductConstructor)+import Data.Functor.ProductIsomorphic.TupleInstances () -- | Restricted functor on products. class ProductIsoFunctor f where@@ -35,3 +44,41 @@ infixl 4 |$|, |*| infixl 3 |||++-- | Empty element of product operator+class ProductIsoApplicative f => ProductIsoEmpty f e where+ pureE :: f e+ peRight :: f (a, e) -> f a+ peLeft :: f (e, a) -> f a++-- | peRight and peRightR should have isomorphic law.+-- @+-- peRight . peRightR == peRightR . peRight == id+-- @+peRightR :: ProductIsoEmpty f e+ => f a+ -> f (a, e)+peRightR p = (,) |$| p |*| pureE+{-# INLINABLE peRightR #-}++-- | peLeft and peLeftR should have isomorphic law.+-- @+-- peLeft . peLeftR == peLeftR . peLeft == id+-- @+peLeftR :: ProductIsoEmpty f e+ => f a+ -> f (e, a)+peLeftR p = (,) |$| pureE |*| p+{-# INLINABLE peLeftR #-}++{-+(<|) :: ProductIsoEmpty f e => f a -> f e -> f a+p <| e = peRight $ (,) |$| p |*| e+{-# INLINABLE (<|) #-}++(|>) :: ProductIsoEmpty f e => f e -> f a -> f a+e |> p = peLeft $ (,) |$| e |*| p+{-# INLINABLE (|>) #-}++infixl 4 <|, |>+ -}
src/Data/Functor/ProductIsomorphic/Instances.hs view
@@ -1,4 +1,5 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE MultiParamTypeClasses #-} -- | -- Module : Data.Functor.ProductIsomorphic.Instances@@ -23,7 +24,8 @@ Const (..)) import Data.Functor.ProductIsomorphic.Class- (ProductIsoFunctor(..), ProductIsoApplicative (..), ProductIsoAlternative (..))+ (ProductIsoFunctor(..), ProductIsoApplicative (..),+ ProductIsoAlternative (..), ProductIsoEmpty (..)) instance ProductIsoFunctor (Const a) where@@ -36,7 +38,15 @@ Const a |*| Const b = Const $ a <> b {-# INLINABLE (|*|) #-} +instance Monoid a => ProductIsoEmpty (Const a) () where+ pureE = pureP ()+ {-# INLINABLE pureE #-}+ peRight (Const a) = Const a+ {-# INLINABLE peRight #-}+ peLeft (Const a) = Const a+ {-# INLINABLE peLeft #-} + -- | Wrapped functor type to make instances of product-iso functors. newtype WrappedFunctor f a = WrapFunctor { unwrapFunctor :: f a } @@ -56,7 +66,15 @@ WrapFunctor fa1 ||| WrapFunctor fa2 = WrapFunctor $ fa1 <|> fa2 {-# INLINABLE (|||) #-} +instance Applicative f => ProductIsoEmpty (WrappedFunctor f) () where+ pureE = pureP ()+ {-# INLINABLE pureE #-}+ peRight = WrapFunctor . fmap fst . unwrapFunctor+ {-# INLINABLE peRight #-}+ peLeft = WrapFunctor . fmap snd . unwrapFunctor+ {-# INLINABLE peLeft #-} + -- | Wrapped Const Alternative objects to make instances like Const functor. newtype WrappedAlter f a b = WrapAlter { unWrapAlter :: Const (f a) b } @@ -69,3 +87,10 @@ {-# INLINABLE pureP #-} WrapAlter (Const a) |*| WrapAlter (Const b) = WrapAlter $ Const $ a <|> b {-# INLINABLE (|*|) #-}++instance Alternative f => ProductIsoEmpty (WrappedAlter f a) () where+ pureE = pureP ()+ {-# INLINABLE pureE #-}+ peRight = WrapAlter . fmap fst . unWrapAlter+ {-# INLINABLE peRight #-}+ peLeft = WrapAlter . fmap snd . unWrapAlter
src/Data/Functor/ProductIsomorphic/TupleInstances.hs view
@@ -16,8 +16,12 @@ import Control.Applicative ((<$>)) +import Data.Functor.ProductIsomorphic.Unsafe (ProductConstructor (..)) import Data.Functor.ProductIsomorphic.TH.Internal (defineTupleProductConstructor) ++instance ProductConstructor () where+ productConstructor = () $(concat <$> mapM defineTupleProductConstructor [2..7])