Stability | experimental |
---|---|
Maintainer | conal@conal.net |
Safe Haskell | None |
Standard building blocks for functors
- newtype Const a b = Const {
- getConst :: a
- data Void a
- voidF :: Void a -> b
- type Unit = Const ()
- unit :: Unit ()
- newtype Id a = 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
- eitherF :: (f a -> b) -> (g a -> b) -> (f :+: g) a -> b
- data (f :*: g) a = (f a) :*: (g a)
- asProd :: (f a, g a) -> (f :*: g) a
- asPair :: (f :*: g) a -> (f a, g a)
- fstF :: (f :*: g) a -> f a
- sndF :: (f :*: g) a -> g a
- newtype (g :. f) a = O (g (f a))
- unO :: :. g f a -> g (f a)
- inO :: (g (f a) -> g' (f' a')) -> :. g f a -> :. g' f' a'
- inO2 :: (g (f a) -> g' (f' a') -> g'' (f'' a'')) -> :. g f a -> :. g' f' a' -> :. g'' f'' a''
- (~>) :: Category cat => cat a' a -> cat b b' -> cat a b -> cat a' b'
- (<~) :: Category cat => cat b b' -> cat a' a -> cat a b -> cat a' b'
- data Lift a = Lift {
- unLift :: a
- data (f :*:! g) a = !(f a) :*:! !(g a)
- data (f :+:! g) a
- eitherF' :: (f a -> c) -> (g a -> c) -> (f :+:! g) a -> c
- pairF :: (f a, g a) -> (f :*: g) a
- unPairF :: (f :*: g) a -> (f a, g a)
- inProd :: ((f a, g a) -> (h b, i b)) -> (f :*: g) a -> (h :*: i) b
- inProd2 :: ((f a, g a) -> (h b, i b) -> (j c, k c)) -> (f :*: g) a -> (h :*: i) b -> (j :*: k) c
- class EncodeF f where
Documentation
newtype Const a b
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) |
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.
Id a |
Sum on unary type constructors
(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) |
Product on unary type constructors
(f a) :*: (g a) |
(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) |
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.
O (g (f a)) |
(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) |
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.
Add a bottom to a type
Strict product functor
!(f a) :*:! !(g a) |
Strict sum functor