packages feed

barbies 1.1.0.0 → 1.1.1.0

raw patch · 6 files changed

+48/−4 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Barbie: bmapC :: forall c b f g. (AllB c b, ConstraintsB b) => (forall a. c a => f a -> g a) -> b f -> b g
+ Data.Barbie.Constraints: bmapC :: forall c b f g. (AllB c b, ConstraintsB b) => (forall a. c a => f a -> g a) -> b f -> b g

Files

ChangeLog.md view
@@ -1,5 +1,8 @@ # Changelog for barbies +## 1.1.1.0+  - Add `bmapC` (Chris Penner).+ ## 1.1.0.0   - Make all classes poly-kinded (#7): a barbie can now be any type      parameterised by a type `(k -> Type)`. In particular, a (higher-kinded)
barbies.cabal view
@@ -1,5 +1,5 @@ name:           barbies-version:        1.1.0.0+version:        1.1.1.0 synopsis:       Classes for working with types that can change clothes. description:    Types that are parametric on a functor are like Barbies that have an outfit for each role. This package provides the basic abstractions to work with them comfortably. category:       Data-structures
src/Data/Barbie.hs view
@@ -80,6 +80,8 @@     -- * Constraints and instance dictionaries   , ConstraintsB(AllB, baddDicts)   , AllBF+    -- ** Utility functions+  , bmapC      -- * Products and constaints   , ProductBC(bdicts)@@ -106,7 +108,7 @@  where -import Data.Barbie.Internal.Constraints(ConstraintsB(..), AllBF)+import Data.Barbie.Internal.Constraints(ConstraintsB(..), AllBF, bmapC) import qualified Data.Barbie.Internal.Constraints as Deprecated  import Data.Barbie.Internal.Functor(FunctorB(..))
src/Data/Barbie/Constraints.hs view
@@ -30,6 +30,7 @@     -- * Retrieving dictionaries   , ConstraintsB(..)   , ProductBC(..)+  , bmapC    , AllBF   , ClassF
src/Data/Barbie/Internal/Constraints.hs view
@@ -4,6 +4,7 @@ {-# LANGUAGE UndecidableInstances #-} module Data.Barbie.Internal.Constraints   ( ConstraintsB(..)+  , bmapC   , AllBF    , CanDeriveConstraintsB@@ -20,7 +21,7 @@  where -import Data.Barbie.Internal.Dicts   (ClassF, Dict (..))+import Data.Barbie.Internal.Dicts   (ClassF, Dict (..), requiringDict) import Data.Barbie.Internal.Functor (FunctorB (..))  import Data.Functor.Compose (Compose (..))@@ -85,6 +86,29 @@        )     => b f -> b (Dict c `Product` f)   baddDicts = gbaddDictsDefault+++-- | Like 'bmap' but a constraint is allowed to be required on+--   each element of @b@+--+-- E.g. If all fields of 'b' are 'Show'able then you +-- could store each shown value in it's slot using 'Const':+--+-- > showFields :: (AllB Show b, ConstraintsB b) => b Identity -> b (Const String)+-- > showFields = bmapC @Show showField+-- >   where+-- >     showField :: forall a. Show a => Identity a -> Const String a+-- >     showField (Identity a) = Const (show a)+bmapC :: forall c b f g.+      (AllB c b, ConstraintsB b)+      => (forall a. c a => f a -> g a)+      -> b f+      -> b g+bmapC f bf = bmap go (baddDicts bf)+  where+    go :: forall a. (Dict c `Product` f) a -> g a+    go (d `Pair` fa) = requiringDict (f fa) d+  -- | Similar to 'AllB' but will put the functor argument @f@ --   between the constraint @c@ and the type @a@. For example:
test/Spec.hs view
@@ -11,9 +11,10 @@ import Barbies import BarbiesW -import Data.Barbie (bfoldMap)+import Data.Barbie (bfoldMap, bmapC, buniqC) import Data.Barbie.Bare(Covered) import Data.Functor.Const(Const(..))+import Data.Functor.Identity(Identity(..))  main :: IO () main@@ -181,4 +182,17 @@                 let b = Record3 (Const "tic") (Const "tac") (Const "toe")                 bfoldMap getConst b @?= "tictactoe"             ]+        , testGroup+          "bmapC"+          [ testCase "Record1" $+                bmapC @Num (fmap (+1)) (Record1 (Identity 0))+                    @?= Record1 (Identity 1)+          ]+        , testGroup+          "buniqC"+          [ testCase "Record1" $+                buniqC @Num (Identity (fromIntegral (42 :: Int)))+                    @?= Record1 (Identity 42)+          ]         ]+