functor-combo-0.3: Functor combinators with tries & zippers

Stabilityexperimental
Maintainerconal@conal.net
Safe HaskellNone

FunctorCombo.Functor

Description

Standard building blocks for functors

Synopsis

Documentation

newtype Const a b

Constructors

Const 

Fields

getConst :: a
 

Instances

Functor (Const m) 
(Functor (Const m), Monoid m) => Applicative (Const m) 
Foldable (Const b) 
(Functor (Const b), Foldable (Const b)) => Traversable (Const b) 
Scan (Const x) 
Functor (Const z) => Holey (Const z) 
Functor (Const x) => Holey (Const x) 
Monoid o => Monoid (Const o a) 
(Functor (Trie (Const x a)), HasTrie x) => HasTrie (Const x a) 
(Functor (STrie (Const x a)), HasTrie x) => HasTrie (Const x a) 

data Void a Source

Empty/zero type constructor (no inhabitants)

Instances

voidF :: Void a -> bSource

type Unit = Const ()Source

Unit type constructor (one inhabitant)

unit :: Unit ()Source

The unit value

newtype Id a

Identity type constructor. Until there's a better place to find it. I'd use Control.Monad.Identity, but I don't want to introduce a dependency on mtl just for Id.

Constructors

Id a 

unId :: Id a -> a

inId :: (a -> b) -> Id a -> Id b

inId2 :: (a -> b -> c) -> Id a -> Id b -> Id c

data (f :+: g) a Source

Sum on unary type constructors

Constructors

InL (f a) 
InR (g a) 

Instances

(Functor f, Functor g) => Functor (:+: f g) 
(Foldable f, Foldable g) => Foldable (:+: f g) 
(Functor (:+: f g), Foldable (:+: f g), Traversable f, Traversable g) => Traversable (:+: f g) 
(Scan f, Scan g) => Scan (:+: f g) 
(Functor (:+: f g), Holey f, Holey g) => Holey (:+: f g) 
(Functor (:+: f g), Holey f, Holey g) => Holey (:+: f g) 
(Show (f a), Show (g a)) => Show (:+: f g a) 
(Functor (Trie (:+: f g a)), HasTrie (f a), HasTrie (g a)) => HasTrie (:+: f g a) 
(Functor (STrie (:+: f g a)), HasTrie (f a), HasTrie (g a)) => HasTrie (:+: f g a) 

eitherF :: (f a -> b) -> (g a -> b) -> (f :+: g) a -> bSource

data (f :*: g) a Source

Product on unary type constructors

Constructors

(f a) :*: (g a) 

Instances

(Functor f, Functor g, Monad f, Monad g) => Monad (:*: f g) 
(Functor f, Functor g) => Functor (:*: f g) 
(Functor (:*: f g), Applicative f, Applicative g) => Applicative (:*: f g) 
(Foldable f, Foldable g) => Foldable (:*: f g) 
(Functor (:*: f g), Foldable (:*: f g), Traversable f, Traversable g) => Traversable (:*: f g) 
(Scan f, Scan g, Functor f, Functor g) => Scan (:*: f g) 
(HasLubF f, HasLubF g) => HasLubF (:*: f g) 
(Functor (:*: f g), Holey f, Holey g) => Holey (:*: f g) 
(Functor (:*: f g), Holey f, Holey g) => Holey (:*: f g) 
(Show (f a), Show (g a)) => Show (:*: f g a) 
(Functor (Trie (:*: f g a)), HasTrie (f a), HasTrie (g a)) => HasTrie (:*: f g a) 
(Functor (STrie (:*: f g a)), HasTrie (f a), HasTrie (g a)) => HasTrie (:*: f g a) 

asProd :: (f a, g a) -> (f :*: g) aSource

asPair :: (f :*: g) a -> (f a, g a)Source

fstF :: (f :*: g) a -> f aSource

Like fst

sndF :: (f :*: g) a -> g aSource

Like snd

newtype (g :. f) a

Composition of unary type constructors

There are (at least) two useful Monoid instances, so you'll have to pick one and type-specialize it (filling in all or parts of g and/or f).

     -- standard Monoid instance for Applicative applied to Monoid
     instance (Applicative (g :. f), Monoid a) => Monoid ((g :. f) a) where
       { mempty = pure mempty; mappend = liftA2 mappend }
     -- Especially handy when g is a Monoid_f.
     instance Monoid (g (f a)) => Monoid ((g :. f) a) where
       { mempty = O mempty; mappend = inO2 mappend }

Corresponding to the first and second definitions above,

     instance (Applicative g, Monoid_f f) => Monoid_f (g :. f) where
       { mempty_f = O (pure mempty_f); mappend_f = inO2 (liftA2 mappend_f) }
     instance Monoid_f g => Monoid_f (g :. f) where
       { mempty_f = O mempty_f; mappend_f = inO2 mappend_f }

Similarly, there are two useful Functor instances and two useful ContraFunctor instances.

     instance (      Functor g,       Functor f) => Functor (g :. f) where fmap = fmapFF
     instance (ContraFunctor g, ContraFunctor f) => Functor (g :. f) where fmap = fmapCC
 
     instance (      Functor g, ContraFunctor f) => ContraFunctor (g :. f) where contraFmap = contraFmapFC
     instance (ContraFunctor g,       Functor f) => ContraFunctor (g :. f) where contraFmap = contraFmapCF

However, it's such a bother to define the Functor instances per composition type, I've left the fmapFF case in. If you want the fmapCC one, you're out of luck for now. I'd love to hear a good solution. Maybe someday Haskell will do Prolog-style search for instances, subgoaling the constraints, rather than just matching instance heads.

Constructors

O (g (f a)) 

Instances

(Functor g, Functor f) => Functor (:. g f) 
(Functor (:. g f), Applicative g, Applicative f) => Applicative (:. g f) 
(Foldable g, Foldable f, Functor g) => Foldable (:. g f) 
(Functor (:. g f), Foldable (:. g f), Traversable g, Traversable f) => Traversable (:. g f) 
(Scan g, Scan f, Functor f, Applicative g) => Scan (:. g f) 
(Functor (:. g f), Holey f, Holey g) => Holey (:. g f) 
(Functor (:. g f), Holey f, Holey g) => Holey (:. g f) 
Eq (g (f a)) => Eq (:. g f a) 
Show (g (f a)) => Show (:. g f a) 
(Functor (Trie (:. g f a)), HasTrie (g (f a))) => HasTrie (:. g f a) 
(Functor (STrie (:. g f a)), HasTrie (g (f a))) => HasTrie (:. g f a) 

unO :: :. g f a -> g (f a)

Unwrap a '(:.)'.

inO :: (g (f a) -> g' (f' a')) -> :. g f a -> :. g' f' a'

Apply a unary function within the O constructor.

inO2 :: (g (f a) -> g' (f' a') -> g'' (f'' a'')) -> :. g f a -> :. g' f' a' -> :. g'' f'' a''

Apply a binary function within the O constructor.

(~>) :: Category cat => cat a' a -> cat b b' -> cat a b -> cat a' b'

Add pre- and post processing

(<~) :: Category cat => cat b b' -> cat a' a -> cat a b -> cat a' b'

data Lift a Source

Add a bottom to a type

Constructors

Lift 

Fields

unLift :: a
 

Instances

data (f :*:! g) a Source

Strict product functor

Constructors

!(f a) :*:! !(g a) 

Instances

(Functor f, Functor g) => Functor (:*:! f g) 
(Functor (STrie (:*:! f g a)), HasTrie (f a), HasTrie (g a)) => HasTrie (:*:! f g a) 

data (f :+:! g) a Source

Strict sum functor

Constructors

InL' !(f a) 
InR' !(g a) 

Instances

(Functor f, Functor g) => Functor (:+:! f g) 
(Functor (STrie (:+:! f g a)), HasTrie (f a), HasTrie (g a)) => HasTrie (:+:! f g a) 

eitherF' :: (f a -> c) -> (g a -> c) -> (f :+:! g) a -> cSource

Case analysis on strict sum functor

pairF :: (f a, g a) -> (f :*: g) aSource

unPairF :: (f :*: g) a -> (f a, g a)Source

inProd :: ((f a, g a) -> (h b, i b)) -> (f :*: g) a -> (h :*: i) bSource

inProd2 :: ((f a, g a) -> (h b, i b) -> (j c, k c)) -> (f :*: g) a -> (h :*: i) b -> (j :*: k) cSource

class EncodeF f whereSource

Associated Types

type Enc f :: * -> *Source

Methods

encode :: f a -> Enc f aSource

decode :: Enc f a -> f aSource

Instances