packages feed

barbies 2.0.1.0 → 2.0.2.0

raw patch · 6 files changed

+64/−10 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Barbies.Bare: type family Wear t f a
+ Barbies.Bare: type family WearTwo t f g a

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for barbies +## 2.0.2.0+  - Add `Barbies.Bare.WearTwo` type family to support having _field-specific_+    newtype wrappers that get applied only to the covered barbie (Lennart+    Spitzner).+ ## 2.0.1.0   - Add the `DistributiveB` class (Gergő Érdi). 
barbies.cabal view
@@ -1,5 +1,5 @@ name:           barbies-version:        2.0.1.0+version:        2.0.2.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/Barbies/Bare.hs view
@@ -17,7 +17,7 @@ --   'Wear' 'Covered' f a = f a -- -- data SignUpForm t f---   = SignUpForm'+--   = SignUpForm --       { username  :: 'Wear' t f 'String', --       , password  :: 'Wear' t f 'String' --       , mailingOk :: 'Wear' t f 'Bool'@@ -27,8 +27,8 @@ --  ..., --  instance 'BareB' SignUpForm ----- type SignUpRaw  = SignUpForm 'Maybe'--- type SignUpData = SignUpForm 'Bare'+-- type SignUpRaw  = SignUpForm 'Covered' 'Maybe'+-- type SignUpData = SignUpForm 'Bare' 'Identity' -- -- formData = SignUpForm "jbond" "shaken007" False :: SignUpData -- @@@ -44,10 +44,13 @@   , bstripFrom   , bcoverWith +  , WearTwo+   ) where  import Barbies.Internal.BareB   ( Wear, Bare, Covered   , BareB(..)   , bstripFrom, bcoverWith+  , WearTwo   )
src/Barbies/Generics/Bare.hs view
@@ -8,7 +8,7 @@  import Data.Functor.Identity (Identity(..)) -import Data.Coerce (coerce)+import Data.Coerce (Coercible, coerce) import Data.Generics.GenericN import Data.Proxy (Proxy(..)) import GHC.TypeLits (Nat)@@ -67,7 +67,7 @@  type P = Param -instance GBare n (Rec (P n Identity a) (Identity a)) (Rec a a) where+instance Coercible a b => GBare n (Rec (P n Identity a) (Identity a)) (Rec b b) where   gstrip _ = coerce   {-# INLINE gstrip #-} 
src/Barbies/Internal/BareB.hs view
@@ -5,6 +5,7 @@   ( Wear, Bare, Covered   , BareB(..)   , bstripFrom, bcoverWith+  , WearTwo    , gbstripDefault   , gbcoverDefault@@ -16,7 +17,7 @@  import Barbies.Generics.Bare(GBare(..)) import Barbies.Internal.FunctorB (FunctorB(..))-import Barbies.Internal.Wear(Bare, Covered, Wear)+import Barbies.Internal.Wear(Bare, Covered, Wear, WearTwo) import Data.Functor.Identity (Identity(..))  import Data.Generics.GenericN
src/Barbies/Internal/Wear.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE TypeFamilies         #-} {-# LANGUAGE UndecidableInstances #-} module Barbies.Internal.Wear-  ( Wear, Bare, Covered+  ( Wear, Bare, Covered, WearTwo   )  where@@ -33,11 +33,56 @@ -- B { f1 :: 5, f2 = 'True' } :: B 'Bare' f -- @ type family Wear t f a where-  Wear Bare    f a = a-  Wear Covered f a = f a+  Wear Bare        f a = a+  Wear Covered     f a = f a   Wear (Param _ t) f a = Wear t f a   Wear t       _ _ = TypeError (     'Text "`Wear` should only be used with "                                ':<>: 'Text "`Bare` or `Covered`."                                ':$$: 'Text "`" ':<>: 'ShowType t ':<>: 'Text "`"                                ':<>: 'Text " is not allowed in this context."                                )++-- | Like the `Wear` family, but with two wrappers @f@ and @g@ instead of one.+-- This is useful if you have a data-type where @f@ is parametric but @g@ is+-- not, consider this:+--+-- @+-- data T t f =+--   T { f1 :: 'Wear'    t f [Bool]+--     , f2 :: 'Wear'    t f (Sum Int)+--     , f3 :: 'WearTwo' t f Sum Int+--     , f4 :: 'WearTwo' t f Max Int+--     }+-- @+--+-- with @x :: T Covered Option@ we would have+--+-- @+-- f1 x :: IO (Option [Bool])+-- f2 x :: IO (Option (Sum Int))+-- f3 x :: IO (Option (Sum Int))+-- f4 x :: IO (Option (Max Int))+-- @+--+-- and with @y :: T Bare Identity@ we would have+--+-- @+-- f1 y :: Int+-- f2 y :: Sum Int+-- f3 y :: Int+-- f4 y :: Int+-- @+--+-- Note how @(Option (Sum Int))@ (or @Max@) has a nice Semigroup instance that+-- we can use to merge two (covered) barbies,+-- while `WearTwo` removes the wrapper for the bare barbie.+type family WearTwo t f g a where+  WearTwo Bare        f g a = a+  WearTwo Covered     f g a = f (g a)+  WearTwo (Param _ t) f g a = WearTwo t f g a+  WearTwo t           _ _ _ =+    TypeError (     'Text "`WearTwo` should only be used with "+              ':<>: 'Text "`Bare` or `Covered`."+              ':$$: 'Text "`" ':<>: 'ShowType t ':<>: 'Text "`"+              ':<>: 'Text " is not allowed in this context."+              )