Community
Modules 26

Data.Functor.Extend

provisional

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

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

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)).

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

Generic extended. Caveats are the same as for gduplicated.

Instances

31
  • instance Extend []
  • instance Extend (Tagged a)
  • instance Extend Proxy
  • instance Extend Maybe
  • instance Extend (Either a)
  • instance Extend ((,) e)
  • instance Semigroup m => Extend ((->) m)
  • instance Extend Seq
  • instance Extend Tree
  • instance Extend w => Extend (EnvT e w)
  • instance Extend w => Extend (StoreT s w)
  • instance (Extend w, Semigroup m) => Extend (TracedT m w)
  • instance Extend Identity
  • instance Extend w => Extend (IdentityT w)
  • instance Extend NonEmpty
  • instance (Extend f, Extend g) => Extend (Functor.Sum f g)
  • instance (Extend f, Extend g) => Extend (f :+: g)
  • instance Extend (Generics.K1 i c)
  • instance Extend Generics.U1
  • instance Extend Generics.V1
  • instance Extend f => Extend (Generics.M1 i t f)
  • instance Extend Par1
  • instance Extend f => Extend (Rec1 f)
  • instance Extend Monoid.Sum
  • instance Extend Monoid.Product
  • instance Extend Monoid.Dual
  • instance Extend f => Extend (Monoid.Alt f)
  • instance Extend Semigroup.First
  • instance Extend Semigroup.Last
  • instance Extend Semigroup.Min
  • instance Extend Semigroup.Max
Maintainer
Edward Kmett <ekmett@gmail.com>
Portability
portable
Copyright
(C) 2011-2015 Edward Kmett
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 4ac4693dc44e2bb370a93502d1bf29784374032a00ad7b3d02803e3d433c0b16

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.