Copyright | Original (c) 2010-2011 Patrick Bahr Tom Hvitved; modifications (c) 2020 James Koppel |
---|---|
License | BSD3 |
Safe Haskell | None |
Language | Haskell98 |
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 (f :*: g) a = (f a) :*: (g a)
- type (:=:) f g = (f :<: g, g :<: f)
- class (f :: * -> *) :<: (g :: * -> *) where
- data Sum (fs :: [* -> *]) e where
- data (f :+: g) (a :: *)
- at :: Elem f fs -> Sum fs a -> Maybe (f a)
- caseF :: Alts fs a b -> Sum fs a -> b
- caseCxt :: forall cxt fs a b. All cxt fs => Proxy cxt -> (forall f. cxt f => f a -> b) -> Sum fs a -> b
- caseSumF :: forall cxt f fs a b. (All cxt fs, Functor f) => Proxy cxt -> (forall g. cxt g => g a -> f (g b)) -> Sum fs a -> f (Sum fs b)
- caseSum :: forall cxt fs a b. All cxt fs => Proxy cxt -> (forall g. cxt g => g a -> g b) -> Sum fs a -> Sum fs b
- spl :: f :=: Sum fs => Alts fs a b -> f a -> b
- ffst :: (f :*: g) a -> f a
- fsnd :: (f :*: g) a -> g a
- data Alts (fs :: [* -> *]) e b
- data Alt f e b
- alt :: (f e -> b) -> Alt f e b
- (<|) :: Alt f e b -> Alts fs e b -> Alts (f ': fs) e b
- cons :: Alt f e b -> Alts fs e b -> Alts (f ': fs) e b
- nil :: Alts '[] e b
Documentation
data (f :*: g) a infixr 8 Source #
Formal product of signatures (functors).
Constructors
(f a) :*: (g a) infixr 8 |
Instances
(Functor f, Functor g) => Functor (f :*: g) Source # | |
(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 |
type (:=:) f g = (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
.
data Sum (fs :: [* -> *]) e where Source #
See documentation for the mult-sorted version, Sum
Instances
(Functor f, Mem f fs) => f :<: (Sum fs) Source # | |
All Functor fs => Functor (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 # | |
caseF :: Alts fs a b -> Sum fs a -> b Source #
Utility function to case on a functor sum, without exposing the internal representation of sums.
caseCxt :: forall cxt fs a b. All cxt fs => Proxy cxt -> (forall f. cxt f => f a -> b) -> Sum fs a -> b Source #
caseSumF :: forall cxt f fs a b. (All cxt fs, Functor f) => Proxy cxt -> (forall g. cxt g => g a -> f (g b)) -> Sum fs a -> f (Sum fs b) Source #
caseSum :: forall cxt fs a b. All cxt fs => Proxy cxt -> (forall g. cxt g => g a -> g b) -> Sum fs a -> Sum fs b Source #