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 = 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:
Will not compile if w is a product type.
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 Proxyinstance Extend Maybeinstance Extend (Either a)instance Extend ((,) e)instance Semigroup m => Extend ((->) m)instance Extend Seqinstance Extend Treeinstance Extend w => Extend (EnvT e w)instance Extend w => Extend (StoreT s w)instance (Extend w, Semigroup m) => Extend (TracedT m w)instance Extend Identityinstance Extend w => Extend (IdentityT w)instance Extend NonEmptyinstance (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.U1instance Extend Generics.V1instance Extend f => Extend (Generics.M1 i t f)instance Extend Par1instance Extend f => Extend (Rec1 f)instance Extend Monoid.Suminstance Extend Monoid.Productinstance Extend Monoid.Dualinstance Extend f => Extend (Monoid.Alt f)instance Extend Semigroup.Firstinstance Extend Semigroup.Lastinstance Extend Semigroup.Mininstance Extend Semigroup.Max
- Maintainer
- Edward Kmett <ekmett@gmail.com>
- Portability
- portable
- Copyright
- (C) 2011-2015 Edward Kmett
- License
- BSD-style (see the file LICENSE)