rank2classes 1.3.1 → 1.3.1.1
raw patch · 3 files changed
+145/−1 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- CHANGELOG.md +4/−0
- rank2classes.cabal +2/−1
- src/Rank2.hs +139/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+Version 1.3.1.1+---------------+* Fixed the doctests after cabal get+ Version 1.3.1 --------------- * Added missing markdown-unlit dependency
rank2classes.cabal view
@@ -1,5 +1,5 @@ name: rank2classes-version: 1.3.1+version: 1.3.1.1 synopsis: standard type constructor class hierarchy, only with methods of rank 2 types description: A mirror image of the standard type constructor class hierarchy rooted in 'Functor', except with methods of rank 2@@ -46,6 +46,7 @@ hs-source-dirs: test default-language: Haskell2010 main-is: Doctest.hs+ other-modules: README ghc-options: -threaded -pgmL markdown-unlit build-depends: base, rank2classes, doctest >= 0.8 build-tool-depends: markdown-unlit:markdown-unlit >= 0.5 && < 0.6
src/Rank2.hs view
@@ -7,6 +7,7 @@ -- the two less standard classes 'Apply' and 'Distributive'. {-# LANGUAGE DefaultSignatures, InstanceSigs, KindSignatures, PolyKinds, Rank2Types #-} {-# LANGUAGE ScopedTypeVariables, TypeOperators #-}+{-# LANGUAGE EmptyCase #-} module Rank2 ( -- * Rank 2 classes Functor(..), Apply(..), Applicative(..),@@ -30,6 +31,8 @@ import Data.Functor.Const (Const(..)) import Data.Functor.Product (Product(Pair)) import Data.Functor.Sum (Sum(InL, InR))+import Data.Proxy (Proxy(..))+import qualified GHC.Generics as Generics import Prelude hiding (Foldable(..), Traversable(..), Functor(..), Applicative(..), (<$>), fst, snd) @@ -198,6 +201,9 @@ instance Functor Empty where _ <$> _ = Empty +instance Functor Proxy where+ _ <$> _ = Proxy+ instance Functor (Const a) where _ <$> Const a = Const a @@ -214,9 +220,37 @@ f <$> InL g = InL (f <$> g) f <$> InR h = InR (f <$> h) +instance Functor Generics.V1 where+ (<$>) _ = coerce+ +instance Functor Generics.U1 where+ (<$>) _ = coerce++instance Functor (Generics.K1 i c) where+ (<$>) _ = coerce++instance Functor f => Functor (Generics.M1 i c f) where+ f <$> Generics.M1 x = Generics.M1 (f <$> x)++instance Functor f => Functor (Generics.Rec1 f) where+ f <$> Generics.Rec1 x = Generics.Rec1 (f <$> x)++-- instance (Rank1.Functor f, Functor g) => Functor ((Generics.:.:) f g) where+-- f <$> Generics.Comp1 x = Generics.Comp1 (Rank1.fmap (f <$>) x)++instance (Functor f, Functor g) => Functor ((Generics.:+:) f g) where+ f <$> Generics.L1 x = Generics.L1 (f <$> x)+ f <$> Generics.R1 x = Generics.R1 (f <$> x)++instance (Functor f, Functor g) => Functor ((Generics.:*:) f g) where+ f <$> (x Generics.:*: y) = f <$> x Generics.:*: f <$> y+ instance Foldable Empty where foldMap _ _ = mempty +instance Foldable Proxy where+ foldMap _ _ = mempty+ instance Foldable (Const x) where foldMap _ _ = mempty @@ -233,9 +267,34 @@ foldMap f (InL g) = foldMap f g foldMap f (InR h) = foldMap f h +instance Foldable Generics.V1 where+ foldMap _ v = case v of {}+ +instance Foldable Generics.U1 where+ foldMap _ _ = mempty++instance Foldable (Generics.K1 i c) where+ foldMap _ _ = mempty++instance Foldable f => Foldable (Generics.M1 i c f) where+ foldMap f (Generics.M1 x) = foldMap f x++instance Foldable f => Foldable (Generics.Rec1 f) where+ foldMap f (Generics.Rec1 x) = foldMap f x++instance (Foldable f, Foldable g) => Foldable ((Generics.:+:) f g) where+ foldMap f (Generics.L1 x) = foldMap f x+ foldMap f (Generics.R1 x) = foldMap f x++instance (Foldable f, Foldable g) => Foldable ((Generics.:*:) f g) where+ foldMap f (x Generics.:*: y) = foldMap f x <> foldMap f y+ instance Traversable Empty where traverse _ _ = Rank1.pure Empty +instance Traversable Proxy where+ traverse _ _ = Rank1.pure Proxy+ instance Traversable (Const x) where traverse _ (Const x) = Rank1.pure (Const x) @@ -252,10 +311,36 @@ traverse f (InL g) = InL Rank1.<$> traverse f g traverse f (InR h) = InR Rank1.<$> traverse f h +instance Traversable Generics.V1 where+ traverse _ = Rank1.pure . coerce+ +instance Traversable Generics.U1 where+ traverse _ = Rank1.pure . coerce++instance Traversable (Generics.K1 i c) where+ traverse _ = Rank1.pure . coerce++instance Traversable f => Traversable (Generics.M1 i c f) where+ traverse f (Generics.M1 x) = Rank1.fmap Generics.M1 (traverse f x)++instance Traversable f => Traversable (Generics.Rec1 f) where+ traverse f (Generics.Rec1 x) = Rank1.fmap Generics.Rec1 (traverse f x)++instance (Traversable f, Traversable g) => Traversable ((Generics.:+:) f g) where+ traverse f (Generics.L1 x) = Rank1.fmap Generics.L1 (traverse f x)+ traverse f (Generics.R1 x) = Rank1.fmap Generics.R1 (traverse f x)++instance (Traversable f, Traversable g) => Traversable ((Generics.:*:) f g) where+ traverse f (x Generics.:*: y) = Rank1.liftA2 (Generics.:*:) (traverse f x) (traverse f y)+ instance Apply Empty where _ <*> _ = Empty liftA2 _ _ _ = Empty +instance Apply Proxy where+ _ <*> _ = Proxy+ liftA2 _ _ _ = Proxy+ instance Semigroup x => Apply (Const x) where Const x <*> Const y = Const (x <> y) liftA2 _ (Const x) (Const y) = Const (x <> y)@@ -273,9 +358,30 @@ liftA2 f (Pair g1 h1) ~(Pair g2 h2) = Pair (liftA2 f g1 g2) (liftA2 f h1 h2) liftA3 f (Pair g1 h1) ~(Pair g2 h2) ~(Pair g3 h3) = Pair (liftA3 f g1 g2 g3) (liftA3 f h1 h2 h3) +instance Apply Generics.V1 where+ (<*>) _ = coerce+ +instance Apply Generics.U1 where+ (<*>) _ = coerce++instance Semigroup c => Apply (Generics.K1 i c) where+ Generics.K1 x <*> Generics.K1 y = Generics.K1 (x <> y)++instance Apply f => Apply (Generics.M1 i c f) where+ Generics.M1 f <*> Generics.M1 x = Generics.M1 (f <*> x)++instance Apply f => Apply (Generics.Rec1 f) where+ Generics.Rec1 f <*> Generics.Rec1 x = Generics.Rec1 (f <*> x)++instance (Apply f, Apply g) => Apply ((Generics.:*:) f g) where+ (x1 Generics.:*: y1) <*> (x2 Generics.:*: y2) = (x1 <*> x2) Generics.:*: (y1 <*> y2)+ instance Applicative Empty where pure = const Empty +instance Applicative Proxy where+ pure = const Proxy+ instance (Semigroup x, Monoid x) => Applicative (Const x) where pure = const (Const mempty) @@ -288,7 +394,20 @@ instance (Applicative g, Applicative h) => Applicative (Product g h) where pure f = Pair (pure f) (pure f) +instance (Semigroup c, Monoid c) => Applicative (Generics.K1 i c) where+ pure _ = Generics.K1 mempty++instance Applicative f => Applicative (Generics.M1 i c f) where+ pure f = Generics.M1 (pure f)++instance Applicative f => Applicative (Generics.Rec1 f) where+ pure f = Generics.Rec1 (pure f)++instance (Applicative f, Applicative g) => Applicative ((Generics.:*:) f g) where+ pure f = pure f Generics.:*: pure f+ instance DistributiveTraversable Empty+instance DistributiveTraversable Proxy instance DistributiveTraversable (Only x) instance DistributiveTraversable g => DistributiveTraversable (Identity g) where cotraverseTraversable w f = Identity (cotraverseTraversable w $ Rank1.fmap runIdentity f)@@ -296,9 +415,19 @@ cotraverseTraversable w f = Pair (cotraverseTraversable w $ Rank1.fmap fst f) (cotraverseTraversable w $ Rank1.fmap snd f) +instance DistributiveTraversable f => DistributiveTraversable (Generics.M1 i c f) where+ cotraverseTraversable w f = Generics.M1 (cotraverseTraversable w (Rank1.fmap Generics.unM1 f))+instance DistributiveTraversable f => DistributiveTraversable (Generics.Rec1 f) where+ cotraverseTraversable w f = Generics.Rec1 (cotraverseTraversable w (Rank1.fmap Generics.unRec1 f))+instance (DistributiveTraversable f, DistributiveTraversable g) => DistributiveTraversable ((Generics.:*:) f g) where+ cotraverseTraversable w f = cotraverseTraversable w (Rank1.fmap (\(a Generics.:*: _) -> a) f) Generics.:*: cotraverseTraversable w (Rank1.fmap (\(_ Generics.:*: b) -> b) f)+ instance Distributive Empty where cotraverse _ _ = Empty +instance Distributive Proxy where+ cotraverse _ _ = Proxy+ instance Monoid x => DistributiveTraversable (Const x) where cotraverseTraversable _ f = coerce (Rank1.fold f) @@ -310,3 +439,13 @@ instance (Distributive g, Distributive h) => Distributive (Product g h) where cotraverse w f = Pair (cotraverse w $ Rank1.fmap fst f) (cotraverse w $ Rank1.fmap snd f)++instance Monoid c => DistributiveTraversable (Generics.K1 i c) where+ cotraverseTraversable _ f = coerce (Rank1.fold f)++instance Distributive f => Distributive (Generics.M1 i c f) where+ cotraverse w f = Generics.M1 (cotraverse w (Rank1.fmap Generics.unM1 f))+instance Distributive f => Distributive (Generics.Rec1 f) where+ cotraverse w f = Generics.Rec1 (cotraverse w (Rank1.fmap Generics.unRec1 f))+instance (Distributive f, Distributive g) => Distributive ((Generics.:*:) f g) where+ cotraverse w f = cotraverse w (Rank1.fmap (\(a Generics.:*: _) -> a) f) Generics.:*: cotraverse w (Rank1.fmap (\(_ Generics.:*: b) -> b) f)