| Copyright | Original (c) 2010-2011 Patrick Bahr Tom Hvitved; modifications (c) 2020 James Koppel |
|---|---|
| License | BSD3 |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Comp.Ops
Description
This module provides sum and product operators on functors.
The main item of interest is the Sum datatype, a constant-memory implementation of type-level sums.
Synopsis
- data Sum (fs :: [Type -> Type]) e where
- data ((f :: Type -> Type) :+: (g :: Type -> Type)) a
- data ((f :: k -> Type) :*: (g :: k -> Type)) (a :: k) = (f a) :*: (g a)
- class (f :: Type -> Type) :<: (g :: Type -> Type) where
- type (:=:) (f :: Type -> Type) (g :: Type -> Type) = (f :<: g, g :<: f)
- spl :: forall f (fs :: [Type -> Type]) a b. f :=: Sum fs => Alts fs a b -> f a -> b
- ffst :: forall {k} f (g :: k -> Type) (a :: k). (f :*: g) a -> f a
- fsnd :: forall {k} (f :: k -> Type) g (a :: k). (f :*: g) a -> g a
- caseCxt :: forall cxt (fs :: [Type -> Type]) a b. All cxt fs => (forall (f :: Type -> Type). cxt f => f a -> b) -> Sum fs a -> b
- caseSumF :: forall cxt f (fs :: [Type -> Type]) a b. (All cxt fs, Functor f) => (forall (g :: Type -> Type). cxt g => g a -> f (g b)) -> Sum fs a -> f (Sum fs b)
- caseSum :: forall cxt (fs :: [Type -> Type]) a b. All cxt fs => (forall (g :: Type -> Type). cxt g => g a -> g b) -> Sum fs a -> Sum fs b
- at :: forall f (fs :: [Type -> Type]) a. Elem f fs -> Sum fs a -> Maybe (f a)
- caseF :: forall (fs :: [Type -> Type]) a b. Alts fs a b -> Sum fs a -> b
- data Alts (fs :: [Type -> Type]) e b
- data Alt (f :: Type -> Type) e b
- alt :: (f e -> b) -> Alt f e b
- (<|) :: forall (f :: Type -> Type) e b (fs :: [Type -> Type]). Alt f e b -> Alts fs e b -> Alts (f ': fs) e b
- cons :: forall (f :: Type -> Type) e b (fs :: [Type -> Type]). Alt f e b -> Alts fs e b -> Alts (f ': fs) e b
- nil :: Alts ('[] :: [Type -> Type]) e b
Documentation
data Sum (fs :: [Type -> Type]) e where Source #
See documentation for the mult-sorted version, Sum
Constructors
| Sum :: forall (f :: Type -> Type) (fs :: [Type -> Type]) e. Elem f fs -> f e -> Sum fs e |
Instances
| (Functor f, Mem f fs) => f :<: (Sum fs) Source # | |
| All Foldable fs => Foldable (Sum fs) Source # | |
Defined in Data.Comp.Ops Methods fold :: Monoid m => Sum fs m -> m # foldMap :: Monoid m => (a -> m) -> Sum fs a -> m # foldMap' :: Monoid m => (a -> m) -> Sum fs a -> m # foldr :: (a -> b -> b) -> b -> Sum fs a -> b # foldr' :: (a -> b -> b) -> b -> Sum fs a -> b # foldl :: (b -> a -> b) -> b -> Sum fs a -> b # foldl' :: (b -> a -> b) -> b -> Sum fs a -> b # foldr1 :: (a -> a -> a) -> Sum fs a -> a # foldl1 :: (a -> a -> a) -> Sum fs a -> a # elem :: Eq a => a -> Sum fs a -> Bool # maximum :: Ord a => Sum fs a -> a # minimum :: Ord a => Sum fs a -> a # | |
| (All Traversable fs, All Functor fs, All Foldable fs) => Traversable (Sum fs) Source # | |
| All Functor fs => Functor (Sum fs) Source # | |
data ((f :: Type -> Type) :+: (g :: Type -> Type)) a infixr 6 Source #
Data type defining coproducts.
data ((f :: k -> Type) :*: (g :: k -> Type)) (a :: k) infixr 8 Source #
Formal product of signatures (functors).
Constructors
| (f a) :*: (g a) infixr 8 |
Instances
| (Foldable f, Foldable g) => Foldable (f :*: g) Source # | |
Defined in Data.Comp.Ops Methods fold :: Monoid m => (f :*: g) m -> m # foldMap :: Monoid m => (a -> m) -> (f :*: g) a -> m # foldMap' :: Monoid m => (a -> m) -> (f :*: g) a -> m # foldr :: (a -> b -> b) -> b -> (f :*: g) a -> b # foldr' :: (a -> b -> b) -> b -> (f :*: g) a -> b # foldl :: (b -> a -> b) -> b -> (f :*: g) a -> b # foldl' :: (b -> a -> b) -> b -> (f :*: g) a -> b # foldr1 :: (a -> a -> a) -> (f :*: g) a -> a # foldl1 :: (a -> a -> a) -> (f :*: g) a -> a # toList :: (f :*: g) a -> [a] # length :: (f :*: g) a -> Int # elem :: Eq a => a -> (f :*: g) a -> Bool # maximum :: Ord a => (f :*: g) a -> a # minimum :: Ord a => (f :*: g) a -> a # | |
| (Traversable f, Traversable g) => Traversable (f :*: g) Source # | |
Defined in Data.Comp.Ops | |
| (Functor f, Functor g) => Functor (f :*: g) Source # | |
type (:=:) (f :: Type -> Type) (g :: Type -> Type) = (f :<: g, g :<: f) Source #
A constraint f :<: g expresses that the signature f is
subsumed by g, i.e. f can be used to construct elements in g.
caseCxt :: forall cxt (fs :: [Type -> Type]) a b. All cxt fs => (forall (f :: Type -> Type). cxt f => f a -> b) -> Sum fs a -> b Source #
caseSumF :: forall cxt f (fs :: [Type -> Type]) a b. (All cxt fs, Functor f) => (forall (g :: Type -> Type). cxt g => g a -> f (g b)) -> Sum fs a -> f (Sum fs b) Source #
caseSum :: forall cxt (fs :: [Type -> Type]) a b. All cxt fs => (forall (g :: Type -> Type). cxt g => g a -> g b) -> Sum fs a -> Sum fs b Source #
caseF :: forall (fs :: [Type -> Type]) a b. Alts fs a b -> Sum fs a -> b Source #
Utility function to case on a functor sum, without exposing the internal representation of sums.
(<|) :: forall (f :: Type -> Type) e b (fs :: [Type -> Type]). Alt f e b -> Alts fs e b -> Alts (f ': fs) e b #