distributive 0.4.1 → 0.4.2
raw patch · 3 files changed
+70/−4 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- distributive.cabal +4/−4
- src/Data/Distributive.hs +4/−0
- src/Data/Distributive/Generic.hs +62/−0
distributive.cabal view
@@ -1,6 +1,6 @@ name: distributive category: Data Structures-version: 0.4.1+version: 0.4.2 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE@@ -10,8 +10,8 @@ homepage: http://github.com/ekmett/distributive/ bug-reports: http://github.com/ekmett/distributive/issues copyright: Copyright (C) 2011-2014 Edward A. Kmett-synopsis: Haskell 98 Distributive functors -- Dual to Traversable-description: Haskell 98 Distributive functors -- Dual to Traversable+synopsis: Distributive functors -- Dual to Traversable+description: Distributive functors -- Dual to Traversable build-type: Custom extra-source-files: .ghci@@ -38,7 +38,7 @@ transformers-compat >= 0.1 && < 0.2 hs-source-dirs: src- exposed-modules: Data.Distributive+ exposed-modules: Data.Distributive Data.Distributive.Generic if flag(lib-Werror) ghc-options: -Werror
src/Data/Distributive.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleContexts #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Distributive@@ -31,6 +32,9 @@ import Data.Proxy import Data.Tagged +#ifndef HLINT+{-# ANN module "hlint: ignore Use section" #-}+#endif -- | This is the categorical dual of 'Traversable'. --
+ src/Data/Distributive/Generic.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE FlexibleContexts #-}+-----------------------------------------------------------------------------+-- |+-- Module : Data.Distributive+-- Copyright : (C) 2011-2014 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : provisional+-- Portability : portable+--+----------------------------------------------------------------------------+module Data.Distributive.Generic+ ( GDistributive(..)+ , genericDistribute+ ) where++import GHC.Generics++-- | 'distribute' derived from a 'Generic1' type+--+-- This can be used to easily produce a 'Distributive' instance for a+-- type with a 'Generic1' instance,+--+-- > data V2 a = V2 a a deriving (Show, Functor, Generic1)+-- > instance Distributive V2' where distribute = genericDistribute+genericDistribute :: (Functor f, Generic1 g, GDistributive (Rep1 g)) => f (g a) -> g (f a)+genericDistribute = to1 . gdistribute . fmap from1++-- Can't distribute over,+-- * sums (:+:)+-- * K1+class GDistributive g where+ gdistribute :: Functor f => f (g a) -> g (f a)++instance GDistributive U1 where+ gdistribute _ = U1+ {-# INLINE gdistribute #-}++instance (GDistributive a, GDistributive b) => GDistributive (a :*: b) where+ gdistribute f = gdistribute (fmap fstP f) :*: gdistribute (fmap sndP f) where+ fstP (l :*: _) = l+ sndP (_ :*: r) = r+ {-# INLINE gdistribute #-}++instance (Functor a, Functor b, GDistributive a, GDistributive b) => GDistributive (a :.: b) where+ gdistribute = Comp1 . fmap gdistribute . gdistribute . fmap unComp1+ {-# INLINE gdistribute #-}++instance GDistributive Par1 where+ gdistribute = Par1 . fmap unPar1+ {-# INLINE gdistribute #-}++instance GDistributive f => GDistributive (Rec1 f) where+ gdistribute = Rec1 . gdistribute . fmap unRec1+ {-# INLINE gdistribute #-}++instance GDistributive f => GDistributive (M1 i c f) where+ gdistribute = M1 . gdistribute . fmap unM1+ {-# INLINE gdistribute #-}