Data.Functor.Extend

semigroupoids-6.0.0.1: Semigroupoids: Category sans id

Copyright | (C) 2011-2015 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell2010

Data.Functor.Extend

Contents

- Extendable Functors

Description

Synopsis

- class Functor w => Extend w where
  - duplicated :: w a -> w (w a)
  - extended :: (w a -> b) -> w a -> w b
- gduplicated :: (Extend (Rep1 w), Generic1 w) => w a -> w (w a)
- gextended :: (Extend (Rep1 w), Generic1 w) => (w a -> b) -> w a -> w b

# Extendable Functors

There are two ways to define an `Extend` instance:

I. Provide definitions for `extended` satisfying this law:

    extended f . extended g = extended (f . extended g)

II. Alternately, you may choose to provide definitions for `duplicated` satisfying this law:

    duplicated . duplicated = fmap duplicated . duplicated

You may of course, choose to define both `duplicated` and `extended`. In that case you must also satisfy these laws:

    extended f = fmap f . duplicated
    duplicated = extended id

These are the default definitions of `extended` and `duplicated`.

class Functor w => Extend w where #

Minimal complete definition

duplicated | extended

Methods

duplicated :: w a -> w (w a) #

    duplicated = extended id
    fmap (fmap f) . duplicated = duplicated . fmap f

extended :: (w a -> b) -> w a -> w b #

    extended f  = fmap f . duplicated

#### Instances

Instances details

Extend Identity # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Identity a -> Identity (Identity a) # extended :: (Identity a -> b) -> Identity a -> Identity b #
Extend First # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: First a -> First (First a) # extended :: (First a -> b) -> First a -> First b #
Extend Last # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Last a -> Last (Last a) # extended :: (Last a -> b) -> Last a -> Last b #
Extend Max # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Max a -> Max (Max a) # extended :: (Max a -> b) -> Max a -> Max b #
Extend Min # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Min a -> Min (Min a) # extended :: (Min a -> b) -> Min a -> Min b #
Extend Dual # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Dual a -> Dual (Dual a) # extended :: (Dual a -> b) -> Dual a -> Dual b #
Extend Product # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Product a -> Product (Product a) # extended :: (Product a -> b) -> Product a -> Product b #
Extend Sum # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Sum a -> Sum (Sum a) # extended :: (Sum a -> b) -> Sum a -> Sum b #
Extend NonEmpty # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: NonEmpty a -> NonEmpty (NonEmpty a) # extended :: (NonEmpty a -> b) -> NonEmpty a -> NonEmpty b #
Extend Par1 # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Par1 a -> Par1 (Par1 a) # extended :: (Par1 a -> b) -> Par1 a -> Par1 b #
Extend Seq # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Seq a -> Seq (Seq a) # extended :: (Seq a -> b) -> Seq a -> Seq b #
Extend Tree # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Tree a -> Tree (Tree a) # extended :: (Tree a -> b) -> Tree a -> Tree b #
Extend Maybe # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Maybe a -> Maybe (Maybe a) # extended :: (Maybe a -> b) -> Maybe a -> Maybe b #
Extend List # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: [a] -> [[a]] # extended :: ([a] -> b) -> [a] -> [b] #
Extend (Either a) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Either a a0 -> Either a (Either a a0) # extended :: (Either a a0 -> b) -> Either a a0 -> Either a b #
Extend (Proxy :: Type -> Type) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Proxy a -> Proxy (Proxy a) # extended :: (Proxy a -> b) -> Proxy a -> Proxy b #
Extend (U1 :: Type -> Type) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: U1 a -> U1 (U1 a) # extended :: (U1 a -> b) -> U1 a -> U1 b #
Extend (V1 :: Type -> Type) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: V1 a -> V1 (V1 a) # extended :: (V1 a -> b) -> V1 a -> V1 b #
Extend f => Extend (MaybeApply f) # |
Instance details Defined in Data.Functor.Bind.Class Methods duplicated :: MaybeApply f a -> MaybeApply f (MaybeApply f a) # extended :: (MaybeApply f a -> b) -> MaybeApply f a -> MaybeApply f b #
Extend ((,) e) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: (e, a) -> (e, (e, a)) # extended :: ((e, a) -> b) -> (e, a) -> (e, b) #
Extend f => Extend (Alt f) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Alt f a -> Alt f (Alt f a) # extended :: (Alt f a -> b) -> Alt f a -> Alt f b #
Extend f => Extend (Rec1 f) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Rec1 f a -> Rec1 f (Rec1 f a) # extended :: (Rec1 f a -> b) -> Rec1 f a -> Rec1 f b #
Extend w => Extend (EnvT e w) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: EnvT e w a -> EnvT e w (EnvT e w a) # extended :: (EnvT e w a -> b) -> EnvT e w a -> EnvT e w b #
Extend w => Extend (StoreT s w) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: StoreT s w a -> StoreT s w (StoreT s w a) # extended :: (StoreT s w a -> b) -> StoreT s w a -> StoreT s w b #
(Extend w, Semigroup m) => Extend (TracedT m w) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: TracedT m w a -> TracedT m w (TracedT m w a) # extended :: (TracedT m w a -> b) -> TracedT m w a -> TracedT m w b #
(Extend f, Semigroup a) => Extend (Static f a) # |
Instance details Defined in Data.Semigroupoid.Static Methods duplicated :: Static f a a0 -> Static f a (Static f a a0) # extended :: (Static f a a0 -> b) -> Static f a a0 -> Static f a b #
Extend (Tagged a) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Tagged a a0 -> Tagged a (Tagged a a0) # extended :: (Tagged a a0 -> b) -> Tagged a a0 -> Tagged a b #
Extend w => Extend (IdentityT w) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: IdentityT w a -> IdentityT w (IdentityT w a) # extended :: (IdentityT w a -> b) -> IdentityT w a -> IdentityT w b #
(Extend f, Extend g) => Extend (Sum f g) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: Sum f g a -> Sum f g (Sum f g a) # extended :: (Sum f g a -> b) -> Sum f g a -> Sum f g b #
(Extend f, Extend g) => Extend (f :+: g) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: (f :+: g) a -> (f :+: g) ((f :+: g) a) # extended :: ((f :+: g) a -> b) -> (f :+: g) a -> (f :+: g) b #
Extend (K1 i c :: Type -> Type) # | Since: 5.3.8
Instance details Defined in Data.Functor.Extend Methods duplicated :: K1 i c a -> K1 i c (K1 i c a) # extended :: (K1 i c a -> b) -> K1 i c a -> K1 i c b #
Semigroup m => Extend ((->) m) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: (m -> a) -> m -> (m -> a) # extended :: ((m -> a) -> b) -> (m -> a) -> m -> b #
Extend f => Extend (M1 i t f) # |
Instance details Defined in Data.Functor.Extend Methods duplicated :: M1 i t f a -> M1 i t f (M1 i t f a) # extended :: (M1 i t f a -> b) -> M1 i t f a -> M1 i t f b #

gduplicated :: (Extend (Rep1 w), Generic1 w) => w a -> w (w a) #

Generic `duplicated`. Caveats:

1. Will not compile if `w` is a product type.
2. Will not compile if `w` contains fields where the type variable appears underneath the composition of type constructors (e.g., `f (g a)`).

Since: 5.3.8

gextended :: (Extend (Rep1 w), Generic1 w) => (w a -> b) -> w a -> w b #

Generic `extended`. Caveats are the same as for `gduplicated`.

Since: 5.3.8