License | BSD-style (see the file LICENSE) |
---|---|
Maintainer | sjoerd@w3future.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- data Diag :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type where
- type DiagF f = Diag (Dom f) (Cod f)
- type Cone j k f n = Nat j k (Const j k n) f
- type Cocone j k f n = Nat j k f (Const j k n)
- coneVertex :: Cone j k f n -> Obj k n
- coconeVertex :: Cocone j k f n -> Obj k n
- class (Category j, Category k) => HasLimits j k where
- type Limit f = LimitFam (Dom f) (Cod f) f
- data LimitFunctor (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) = LimitFunctor
- limitAdj :: forall j k. HasLimits j k => Adjunction (Nat j k) k (Diag j k) (LimitFunctor j k)
- adjLimit :: Category k => Adjunction (Nat j k) k (Diag j k) r -> Obj (Nat j k) f -> Cone j k f (r :% f)
- adjLimitFactorizer :: Category k => Adjunction (Nat j k) k (Diag j k) r -> Cone j k f n -> k n (r :% f)
- rightAdjointPreservesLimits :: (HasLimits j c, HasLimits j d) => Adjunction c d f g -> Obj (Nat j c) t -> d (Limit (g :.: t)) (g :% Limit t)
- rightAdjointPreservesLimitsInv :: (HasLimits j c, HasLimits j d) => Obj (Nat c d) g -> Obj (Nat j c) t -> d (g :% LimitFam j c t) (LimitFam j d (g :.: t))
- class (Category j, Category k) => HasColimits j k where
- type ColimitFam (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) (f :: Type) :: Type
- colimit :: Obj (Nat j k) f -> Cocone j k f (ColimitFam j k f)
- colimitFactorizer :: Cocone j k f n -> k (ColimitFam j k f) n
- type Colimit f = ColimitFam (Dom f) (Cod f) f
- data ColimitFunctor (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) = ColimitFunctor
- colimitAdj :: forall j k. HasColimits j k => Adjunction k (Nat j k) (ColimitFunctor j k) (Diag j k)
- adjColimit :: Category k => Adjunction k (Nat j k) l (Diag j k) -> Obj (Nat j k) f -> Cocone j k f (l :% f)
- adjColimitFactorizer :: Category k => Adjunction k (Nat j k) l (Diag j k) -> Cocone j k f n -> k (l :% f) n
- leftAdjointPreservesColimits :: (HasColimits j c, HasColimits j d) => Adjunction c d f g -> Obj (Nat j d) t -> c (f :% Colimit t) (Colimit (f :.: t))
- leftAdjointPreservesColimitsInv :: (HasColimits j c, HasColimits j d) => Obj (Nat d c) f -> Obj (Nat j d) t -> c (ColimitFam j c (f :.: t)) (f :% ColimitFam j d t)
- class Category k => HasTerminalObject k where
- type TerminalObject k :: Kind k
- terminalObject :: Obj k (TerminalObject k)
- terminate :: Obj k a -> k a (TerminalObject k)
- class Category k => HasInitialObject k where
- type InitialObject k :: Kind k
- initialObject :: Obj k (InitialObject k)
- initialize :: Obj k a -> k (InitialObject k) a
- data Zero
- class Category k => HasBinaryProducts k where
- type BinaryProduct k (x :: Kind k) (y :: Kind k) :: Kind k
- proj1 :: Obj k x -> Obj k y -> k (BinaryProduct k x y) x
- proj2 :: Obj k x -> Obj k y -> k (BinaryProduct k x y) y
- (&&&) :: k a x -> k a y -> k a (BinaryProduct k x y)
- (***) :: k a1 b1 -> k a2 b2 -> k (BinaryProduct k a1 a2) (BinaryProduct k b1 b2)
- data ProductFunctor (k :: Type -> Type -> Type) = ProductFunctor
- data p :*: q where
- prodAdj :: HasBinaryProducts k => Adjunction (k :**: k) k (DiagProd k) (ProductFunctor k)
- newtype x & y = AddConj (forall r. Either (x %1 -> r) (y %1 -> r) %1 -> r)
- class Category k => HasBinaryCoproducts k where
- type BinaryCoproduct k (x :: Kind k) (y :: Kind k) :: Kind k
- inj1 :: Obj k x -> Obj k y -> k x (BinaryCoproduct k x y)
- inj2 :: Obj k x -> Obj k y -> k y (BinaryCoproduct k x y)
- (|||) :: k x a -> k y a -> k (BinaryCoproduct k x y) a
- (+++) :: k a1 b1 -> k a2 b2 -> k (BinaryCoproduct k a1 a2) (BinaryCoproduct k b1 b2)
- data CoproductFunctor (k :: Type -> Type -> Type) = CoproductFunctor
- data p :+: q where
- coprodAdj :: HasBinaryCoproducts k => Adjunction k (k :**: k) (CoproductFunctor k) (DiagProd k)
- data Either a b
Preliminairies
Diagonal Functor
data Diag :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type where Source #
type DiagF f = Diag (Dom f) (Cod f) Source #
The diagonal functor with the same domain and codomain as f
.
Cones
type Cone j k f n = Nat j k (Const j k n) f Source #
A cone from N to F is a natural transformation from the constant functor to N to F.
type Cocone j k f n = Nat j k f (Const j k n) Source #
A co-cone from F to N is a natural transformation from F to the constant functor to N.
coneVertex :: Cone j k f n -> Obj k n Source #
The vertex (or apex) of a cone.
coconeVertex :: Cocone j k f n -> Obj k n Source #
The vertex (or apex) of a co-cone.
Limits
class (Category j, Category k) => HasLimits j k where Source #
An instance of HasLimits j k
says that k
has all limits of type j
.
type LimitFam (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) (f :: Type) :: Type Source #
Limits in a category k
by means of a diagram of type j
, which is a functor from j
to k
.
limit :: Obj (Nat j k) f -> Cone j k f (LimitFam j k f) Source #
limit
returns the limiting cone for a functor f
.
limitFactorizer :: Cone j k f n -> k n (LimitFam j k f) Source #
limitFactorizer
shows that the limiting cone is universal – i.e. any other cone of f
factors through it
by returning the morphism between the vertices of the cones.
Instances
Category k => HasLimits Boolean k Source # | The limit of a functor from the Boolean category is the source of the arrow it points to. |
Category k => HasLimits Unit k Source # | The limit of a single object is that object. |
(Category k, HasTerminalObject k) => HasLimits Void k Source # | A terminal object is the limit of the functor from 0 to k. |
(HasLimits i k, HasLimits j k, HasBinaryProducts k) => HasLimits (i :++: j) k Source # | If |
(HasInitialObject (i :>>: j), Category i, Category j, Category k) => HasLimits (i :>>: j) k Source # | The limit of any diagram with an initial object, has the limit at the initial object. |
HasLimits (->) (->) Source # | |
data LimitFunctor (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) Source #
Instances
HasLimits j k => Functor (LimitFunctor j k) Source # | If every diagram of type |
Defined in Data.Category.Limit type Dom (LimitFunctor j k) :: Type -> Type -> Type Source # type Cod (LimitFunctor j k) :: Type -> Type -> Type Source # type (LimitFunctor j k) :% a Source # (%) :: LimitFunctor j k -> Dom (LimitFunctor j k) a b -> Cod (LimitFunctor j k) (LimitFunctor j k :% a) (LimitFunctor j k :% b) Source # | |
type Cod (LimitFunctor j k) Source # | |
Defined in Data.Category.Limit | |
type Dom (LimitFunctor j k) Source # | |
Defined in Data.Category.Limit | |
type (LimitFunctor j k) :% f Source # | |
Defined in Data.Category.Limit |
limitAdj :: forall j k. HasLimits j k => Adjunction (Nat j k) k (Diag j k) (LimitFunctor j k) Source #
The limit functor is right adjoint to the diagonal functor.
adjLimit :: Category k => Adjunction (Nat j k) k (Diag j k) r -> Obj (Nat j k) f -> Cone j k f (r :% f) Source #
adjLimitFactorizer :: Category k => Adjunction (Nat j k) k (Diag j k) r -> Cone j k f n -> k n (r :% f) Source #
rightAdjointPreservesLimits :: (HasLimits j c, HasLimits j d) => Adjunction c d f g -> Obj (Nat j c) t -> d (Limit (g :.: t)) (g :% Limit t) Source #
rightAdjointPreservesLimitsInv :: (HasLimits j c, HasLimits j d) => Obj (Nat c d) g -> Obj (Nat j c) t -> d (g :% LimitFam j c t) (LimitFam j d (g :.: t)) Source #
Colimits
class (Category j, Category k) => HasColimits j k where Source #
An instance of HasColimits j k
says that k
has all colimits of type j
.
type ColimitFam (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) (f :: Type) :: Type Source #
Colimits in a category k
by means of a diagram of type j
, which is a functor from j
to k
.
colimit :: Obj (Nat j k) f -> Cocone j k f (ColimitFam j k f) Source #
colimit
returns the limiting co-cone for a functor f
.
colimitFactorizer :: Cocone j k f n -> k (ColimitFam j k f) n Source #
colimitFactorizer
shows that the limiting co-cone is universal – i.e. any other co-cone of f
factors through it
by returning the morphism between the vertices of the cones.
Instances
Category k => HasColimits Boolean k Source # | The colimit of a functor from the Boolean category is the target of the arrow it points to. |
Defined in Data.Category.Boolean type ColimitFam Boolean k f Source # | |
Category k => HasColimits Unit k Source # | The colimit of a single object is that object. |
Defined in Data.Category.Limit type ColimitFam Unit k f Source # | |
(Category k, HasInitialObject k) => HasColimits Void k Source # | An initial object is the colimit of the functor from 0 to k. |
Defined in Data.Category.Limit type ColimitFam Void k f Source # | |
(HasColimits i k, HasColimits j k, HasBinaryCoproducts k) => HasColimits (i :++: j) k Source # | If |
Defined in Data.Category.Limit type ColimitFam (i :++: j) k f Source # | |
(HasTerminalObject (i :>>: j), Category i, Category j, Category k) => HasColimits (i :>>: j) k Source # | The colimit of any diagram with a terminal object, has the limit at the terminal object. |
Defined in Data.Category.Limit type ColimitFam (i :>>: j) k f Source # | |
HasColimits (->) (->) Source # | |
Defined in Data.Category.Limit type ColimitFam (->) (->) f Source # colimit :: Obj (Nat (->) (->)) f -> Cocone (->) (->) f (ColimitFam (->) (->) f) Source # colimitFactorizer :: Cocone (->) (->) f n -> ColimitFam (->) (->) f -> n Source # |
data ColimitFunctor (j :: Type -> Type -> Type) (k :: Type -> Type -> Type) Source #
Instances
HasColimits j k => Functor (ColimitFunctor j k) Source # | If every diagram of type |
Defined in Data.Category.Limit type Dom (ColimitFunctor j k) :: Type -> Type -> Type Source # type Cod (ColimitFunctor j k) :: Type -> Type -> Type Source # type (ColimitFunctor j k) :% a Source # (%) :: ColimitFunctor j k -> Dom (ColimitFunctor j k) a b -> Cod (ColimitFunctor j k) (ColimitFunctor j k :% a) (ColimitFunctor j k :% b) Source # | |
type Cod (ColimitFunctor j k) Source # | |
Defined in Data.Category.Limit | |
type Dom (ColimitFunctor j k) Source # | |
Defined in Data.Category.Limit | |
type (ColimitFunctor j k) :% f Source # | |
Defined in Data.Category.Limit |
colimitAdj :: forall j k. HasColimits j k => Adjunction k (Nat j k) (ColimitFunctor j k) (Diag j k) Source #
The colimit functor is left adjoint to the diagonal functor.
adjColimit :: Category k => Adjunction k (Nat j k) l (Diag j k) -> Obj (Nat j k) f -> Cocone j k f (l :% f) Source #
adjColimitFactorizer :: Category k => Adjunction k (Nat j k) l (Diag j k) -> Cocone j k f n -> k (l :% f) n Source #
leftAdjointPreservesColimits :: (HasColimits j c, HasColimits j d) => Adjunction c d f g -> Obj (Nat j d) t -> c (f :% Colimit t) (Colimit (f :.: t)) Source #
leftAdjointPreservesColimitsInv :: (HasColimits j c, HasColimits j d) => Obj (Nat d c) f -> Obj (Nat j d) t -> c (ColimitFam j c (f :.: t)) (f :% ColimitFam j d t) Source #
Limits of type Void
class Category k => HasTerminalObject k where Source #
type TerminalObject k :: Kind k Source #
terminalObject :: Obj k (TerminalObject k) Source #
terminate :: Obj k a -> k a (TerminalObject k) Source #
Instances
class Category k => HasInitialObject k where Source #
type InitialObject k :: Kind k Source #
initialObject :: Obj k (InitialObject k) Source #
initialize :: Obj k a -> k (InitialObject k) a Source #
Instances
HasInitialObject Boolean Source # | False is the initial object in the Boolean category. |
Defined in Data.Category.Boolean type InitialObject Boolean :: Kind k Source # initialObject :: Obj Boolean (InitialObject Boolean) Source # initialize :: forall (a :: k). Obj Boolean a -> Boolean (InitialObject Boolean) a Source # | |
HasInitialObject Simplex Source # | The ordinal |
Defined in Data.Category.Simplex type InitialObject Simplex :: Kind k Source # initialObject :: Obj Simplex (InitialObject Simplex) Source # initialize :: forall (a :: k). Obj Simplex a -> Simplex (InitialObject Simplex) a Source # | |
HasInitialObject Unit Source # | The category of one object has that object as initial object. |
Defined in Data.Category.Limit type InitialObject Unit :: Kind k Source # initialObject :: Obj Unit (InitialObject Unit) Source # initialize :: forall (a :: k). Obj Unit a -> Unit (InitialObject Unit) a Source # | |
HasInitialObject (f (Fix f)) => HasInitialObject (Fix f :: Type -> Type -> Type) Source # |
|
Defined in Data.Category.Fix type InitialObject (Fix f) :: Kind k Source # initialObject :: Obj (Fix f) (InitialObject (Fix f)) Source # initialize :: forall (a :: k). Obj (Fix f) a -> Fix f (InitialObject (Fix f)) a Source # | |
(Eq a, Bounded a) => HasInitialObject (Preorder a :: Type -> Type -> Type) Source # | |
Defined in Data.Category.Preorder type InitialObject (Preorder a) :: Kind k Source # initialObject :: Obj (Preorder a) (InitialObject (Preorder a)) Source # initialize :: forall (a0 :: k). Obj (Preorder a) a0 -> Preorder a (InitialObject (Preorder a)) a0 Source # | |
(HasInitialObject c1, Category c2) => HasInitialObject (c1 :>>: c2 :: Type -> Type -> TYPE LiftedRep) Source # | The initial object of the direct coproduct of categories is the initial object of the initial category. |
Defined in Data.Category.Limit type InitialObject (c1 :>>: c2) :: Kind k Source # initialObject :: Obj (c1 :>>: c2) (InitialObject (c1 :>>: c2)) Source # initialize :: forall (a :: k). Obj (c1 :>>: c2) a -> (c1 :>>: c2) (InitialObject (c1 :>>: c2)) a Source # | |
HasInitialObject (Dialg (Tuple1 (->) (->) ()) (DiagProd (->))) Source # | The category for defining the natural numbers and primitive recursion can be described as
|
Defined in Data.Category.Dialg initialObject :: Obj (Dialg (Tuple1 (->) (->) ()) (DiagProd (->))) (InitialObject (Dialg (Tuple1 (->) (->) ()) (DiagProd (->)))) Source # initialize :: forall (a :: k). Obj (Dialg (Tuple1 (->) (->) ()) (DiagProd (->))) a -> Dialg (Tuple1 (->) (->) ()) (DiagProd (->)) (InitialObject (Dialg (Tuple1 (->) (->) ()) (DiagProd (->)))) a Source # | |
(Category c, HasInitialObject d) => HasInitialObject (Nat c d :: Type -> Type -> Type) Source # | The constant functor to the initial object is itself the initial object in its functor category. |
Defined in Data.Category.Limit type InitialObject (Nat c d) :: Kind k Source # initialObject :: Obj (Nat c d) (InitialObject (Nat c d)) Source # initialize :: forall (a :: k). Obj (Nat c d) a -> Nat c d (InitialObject (Nat c d)) a Source # | |
(HasInitialObject c1, HasInitialObject c2) => HasInitialObject (c1 :**: c2 :: Type -> Type -> Type) Source # | The initial object of the product of 2 categories is the product of their initial objects. |
Defined in Data.Category.Limit type InitialObject (c1 :**: c2) :: Kind k Source # initialObject :: Obj (c1 :**: c2) (InitialObject (c1 :**: c2)) Source # initialize :: forall (a :: k). Obj (c1 :**: c2) a -> (c1 :**: c2) (InitialObject (c1 :**: c2)) a Source # | |
HasInitialObject (FUN m :: Type -> Type -> Type) Source # | Any empty data type is an initial object in |
Defined in Data.Category.Limit type InitialObject (FUN m) :: Kind k Source # initialObject :: Obj (FUN m) (InitialObject (FUN m)) Source # initialize :: forall (a :: k). Obj (FUN m) a -> FUN m (InitialObject (FUN m)) a Source # | |
HasTerminalObject k2 => HasInitialObject (Op k2 :: k1 -> k1 -> Type) Source # | Terminal objects are the dual of initial objects. |
Defined in Data.Category.Limit type InitialObject (Op k2) :: Kind k Source # initialObject :: Obj (Op k2) (InitialObject (Op k2)) Source # initialize :: forall (a :: k). Obj (Op k2) a -> Op k2 (InitialObject (Op k2)) a Source # | |
HasInitialObject (LTE ('S n) :: Fin ('S n) -> Fin ('S n) -> Type) Source # | |
Defined in Data.Category.Fin initialObject :: Obj (LTE ('S n)) (InitialObject (LTE ('S n))) Source # initialize :: forall (a :: k). Obj (LTE ('S n)) a -> LTE ('S n) (InitialObject (LTE ('S n))) a Source # | |
HasInitialObject Cat Source # | The empty category is the initial object in |
Defined in Data.Category.Limit type InitialObject Cat :: Kind k Source # initialObject :: Obj Cat (InitialObject Cat) Source # initialize :: forall (a :: k). Obj Cat a -> Cat (InitialObject Cat) a Source # |
Limits of type Pair
class Category k => HasBinaryProducts k where Source #
proj1 :: Obj k x -> Obj k y -> k (BinaryProduct k x y) x Source #
proj2 :: Obj k x -> Obj k y -> k (BinaryProduct k x y) y Source #
(&&&) :: k a x -> k a y -> k a (BinaryProduct k x y) infixl 3 Source #
(***) :: k a1 b1 -> k a2 b2 -> k (BinaryProduct k a1 a2) (BinaryProduct k b1 b2) infixl 3 Source #
Instances
HasBinaryProducts Boolean Source # | Conjunction is the binary product in the Boolean category. |
Defined in Data.Category.Boolean type BinaryProduct Boolean x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj Boolean x -> Obj Boolean y -> Boolean (BinaryProduct Boolean x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj Boolean x -> Obj Boolean y -> Boolean (BinaryProduct Boolean x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). Boolean a x -> Boolean a y -> Boolean a (BinaryProduct Boolean x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Boolean a1 b1 -> Boolean a2 b2 -> Boolean (BinaryProduct Boolean a1 a2) (BinaryProduct Boolean b1 b2) Source # | |
HasBinaryProducts Unit Source # | In the category of one object that object is its own product. |
Defined in Data.Category.Limit type BinaryProduct Unit x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj Unit x -> Obj Unit y -> Unit (BinaryProduct Unit x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj Unit x -> Obj Unit y -> Unit (BinaryProduct Unit x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). Unit a x -> Unit a y -> Unit a (BinaryProduct Unit x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Unit a1 b1 -> Unit a2 b2 -> Unit (BinaryProduct Unit a1 a2) (BinaryProduct Unit b1 b2) Source # | |
HasBinaryProducts (f (Fix f)) => HasBinaryProducts (Fix f :: Type -> Type -> Type) Source # |
|
Defined in Data.Category.Fix type BinaryProduct (Fix f) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (Fix f) x -> Obj (Fix f) y -> Fix f (BinaryProduct (Fix f) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (Fix f) x -> Obj (Fix f) y -> Fix f (BinaryProduct (Fix f) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). Fix f a x -> Fix f a y -> Fix f a (BinaryProduct (Fix f) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Fix f a1 b1 -> Fix f a2 b2 -> Fix f (BinaryProduct (Fix f) a1 a2) (BinaryProduct (Fix f) b1 b2) Source # | |
Ord a => HasBinaryProducts (Preorder a :: Type -> Type -> Type) Source # | |
Defined in Data.Category.Preorder type BinaryProduct (Preorder a) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (Preorder a) x -> Obj (Preorder a) y -> Preorder a (BinaryProduct (Preorder a) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (Preorder a) x -> Obj (Preorder a) y -> Preorder a (BinaryProduct (Preorder a) x y) y Source # (&&&) :: forall (a0 :: k) (x :: k) (y :: k). Preorder a a0 x -> Preorder a a0 y -> Preorder a a0 (BinaryProduct (Preorder a) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Preorder a a1 b1 -> Preorder a a2 b2 -> Preorder a (BinaryProduct (Preorder a) a1 a2) (BinaryProduct (Preorder a) b1 b2) Source # | |
(HasBinaryProducts c1, HasBinaryProducts c2) => HasBinaryProducts (c1 :>>: c2 :: Type -> Type -> TYPE LiftedRep) Source # | |
Defined in Data.Category.Limit type BinaryProduct (c1 :>>: c2) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (c1 :>>: c2) x -> Obj (c1 :>>: c2) y -> (c1 :>>: c2) (BinaryProduct (c1 :>>: c2) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (c1 :>>: c2) x -> Obj (c1 :>>: c2) y -> (c1 :>>: c2) (BinaryProduct (c1 :>>: c2) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). (c1 :>>: c2) a x -> (c1 :>>: c2) a y -> (c1 :>>: c2) a (BinaryProduct (c1 :>>: c2) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). (c1 :>>: c2) a1 b1 -> (c1 :>>: c2) a2 b2 -> (c1 :>>: c2) (BinaryProduct (c1 :>>: c2) a1 a2) (BinaryProduct (c1 :>>: c2) b1 b2) Source # | |
(Category c, HasBinaryProducts d) => HasBinaryProducts (Nat c d :: Type -> Type -> Type) Source # | The functor product |
Defined in Data.Category.Limit type BinaryProduct (Nat c d) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (Nat c d) x -> Obj (Nat c d) y -> Nat c d (BinaryProduct (Nat c d) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (Nat c d) x -> Obj (Nat c d) y -> Nat c d (BinaryProduct (Nat c d) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). Nat c d a x -> Nat c d a y -> Nat c d a (BinaryProduct (Nat c d) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Nat c d a1 b1 -> Nat c d a2 b2 -> Nat c d (BinaryProduct (Nat c d) a1 a2) (BinaryProduct (Nat c d) b1 b2) Source # | |
(HasBinaryProducts c1, HasBinaryProducts c2) => HasBinaryProducts (c1 :**: c2 :: Type -> Type -> Type) Source # | The binary product of the product of 2 categories is the product of their binary products. |
Defined in Data.Category.Limit type BinaryProduct (c1 :**: c2) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (c1 :**: c2) x -> Obj (c1 :**: c2) y -> (c1 :**: c2) (BinaryProduct (c1 :**: c2) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (c1 :**: c2) x -> Obj (c1 :**: c2) y -> (c1 :**: c2) (BinaryProduct (c1 :**: c2) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). (c1 :**: c2) a x -> (c1 :**: c2) a y -> (c1 :**: c2) a (BinaryProduct (c1 :**: c2) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). (c1 :**: c2) a1 b1 -> (c1 :**: c2) a2 b2 -> (c1 :**: c2) (BinaryProduct (c1 :**: c2) a1 a2) (BinaryProduct (c1 :**: c2) b1 b2) Source # | |
HasBinaryProducts (->) Source # | The tuple is the binary product in |
Defined in Data.Category.Limit type BinaryProduct (->) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (->) x -> Obj (->) y -> BinaryProduct (->) x y -> x Source # proj2 :: forall (x :: k) (y :: k). Obj (->) x -> Obj (->) y -> BinaryProduct (->) x y -> y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). (a -> x) -> (a -> y) -> a -> BinaryProduct (->) x y Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). (a1 -> b1) -> (a2 -> b2) -> BinaryProduct (->) a1 a2 -> BinaryProduct (->) b1 b2 Source # | |
HasBinaryProducts (FUN 'One :: Type -> Type -> Type) Source # | The product in the category of linear types is a & b, where you have access to a and b, but not both at the same time. |
Defined in Data.Category.Limit proj1 :: forall (x :: k) (y :: k). Obj (FUN 'One) x -> Obj (FUN 'One) y -> FUN 'One (BinaryProduct (FUN 'One) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (FUN 'One) x -> Obj (FUN 'One) y -> FUN 'One (BinaryProduct (FUN 'One) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). FUN 'One a x -> FUN 'One a y -> FUN 'One a (BinaryProduct (FUN 'One) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). FUN 'One a1 b1 -> FUN 'One a2 b2 -> FUN 'One (BinaryProduct (FUN 'One) a1 a2) (BinaryProduct (FUN 'One) b1 b2) Source # | |
HasBinaryCoproducts k2 => HasBinaryProducts (Op k2 :: k1 -> k1 -> Type) Source # | Binary products are the dual of binary coproducts. |
Defined in Data.Category.Limit type BinaryProduct (Op k2) x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj (Op k2) x -> Obj (Op k2) y -> Op k2 (BinaryProduct (Op k2) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (Op k2) x -> Obj (Op k2) y -> Op k2 (BinaryProduct (Op k2) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). Op k2 a x -> Op k2 a y -> Op k2 a (BinaryProduct (Op k2) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Op k2 a1 b1 -> Op k2 a2 b2 -> Op k2 (BinaryProduct (Op k2) a1 a2) (BinaryProduct (Op k2) b1 b2) Source # | |
HasBinaryProducts (LTE ('S n)) => HasBinaryProducts (LTE ('S ('S n)) :: Fin ('S ('S n)) -> Fin ('S ('S n)) -> Type) Source # | |
Defined in Data.Category.Fin proj1 :: forall (x :: k) (y :: k). Obj (LTE ('S ('S n))) x -> Obj (LTE ('S ('S n))) y -> LTE ('S ('S n)) (BinaryProduct (LTE ('S ('S n))) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (LTE ('S ('S n))) x -> Obj (LTE ('S ('S n))) y -> LTE ('S ('S n)) (BinaryProduct (LTE ('S ('S n))) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). LTE ('S ('S n)) a x -> LTE ('S ('S n)) a y -> LTE ('S ('S n)) a (BinaryProduct (LTE ('S ('S n))) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). LTE ('S ('S n)) a1 b1 -> LTE ('S ('S n)) a2 b2 -> LTE ('S ('S n)) (BinaryProduct (LTE ('S ('S n))) a1 a2) (BinaryProduct (LTE ('S ('S n))) b1 b2) Source # | |
HasBinaryProducts (LTE ('S 'Z)) Source # | |
Defined in Data.Category.Fin proj1 :: forall (x :: k) (y :: k). Obj (LTE ('S 'Z)) x -> Obj (LTE ('S 'Z)) y -> LTE ('S 'Z) (BinaryProduct (LTE ('S 'Z)) x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj (LTE ('S 'Z)) x -> Obj (LTE ('S 'Z)) y -> LTE ('S 'Z) (BinaryProduct (LTE ('S 'Z)) x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). LTE ('S 'Z) a x -> LTE ('S 'Z) a y -> LTE ('S 'Z) a (BinaryProduct (LTE ('S 'Z)) x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). LTE ('S 'Z) a1 b1 -> LTE ('S 'Z) a2 b2 -> LTE ('S 'Z) (BinaryProduct (LTE ('S 'Z)) a1 a2) (BinaryProduct (LTE ('S 'Z)) b1 b2) Source # | |
HasBinaryProducts Cat Source # | The product of categories |
Defined in Data.Category.Limit type BinaryProduct Cat x y :: Kind k Source # proj1 :: forall (x :: k) (y :: k). Obj Cat x -> Obj Cat y -> Cat (BinaryProduct Cat x y) x Source # proj2 :: forall (x :: k) (y :: k). Obj Cat x -> Obj Cat y -> Cat (BinaryProduct Cat x y) y Source # (&&&) :: forall (a :: k) (x :: k) (y :: k). Cat a x -> Cat a y -> Cat a (BinaryProduct Cat x y) Source # (***) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Cat a1 b1 -> Cat a2 b2 -> Cat (BinaryProduct Cat a1 a2) (BinaryProduct Cat b1 b2) Source # |
data ProductFunctor (k :: Type -> Type -> Type) Source #
Instances
(:*:) :: (Functor p, Functor q, Dom p ~ Dom q, Cod p ~ k, Cod q ~ k, HasBinaryProducts k) => p -> q -> p :*: q |
Instances
(Category (Dom p), Category (Cod p)) => Functor (p :*: q) Source # | The product of two functors, passing the same object to both functors and taking the product of the results. |
type Cod (p :*: q) Source # | |
Defined in Data.Category.Limit | |
type Dom (p :*: q) Source # | |
Defined in Data.Category.Limit | |
type (p :*: q) :% a Source # | |
Defined in Data.Category.Limit |
prodAdj :: HasBinaryProducts k => Adjunction (k :**: k) k (DiagProd k) (ProductFunctor k) Source #
A specialisation of the limit adjunction to products.
class Category k => HasBinaryCoproducts k where Source #
inj1 :: Obj k x -> Obj k y -> k x (BinaryCoproduct k x y) Source #
inj2 :: Obj k x -> Obj k y -> k y (BinaryCoproduct k x y) Source #
(|||) :: k x a -> k y a -> k (BinaryCoproduct k x y) a infixl 2 Source #
(+++) :: k a1 b1 -> k a2 b2 -> k (BinaryCoproduct k a1 a2) (BinaryCoproduct k b1 b2) infixl 2 Source #
Instances
HasBinaryCoproducts Boolean Source # | Disjunction is the binary coproduct in the Boolean category. |
Defined in Data.Category.Boolean type BinaryCoproduct Boolean x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj Boolean x -> Obj Boolean y -> Boolean x (BinaryCoproduct Boolean x y) Source # inj2 :: forall (x :: k) (y :: k). Obj Boolean x -> Obj Boolean y -> Boolean y (BinaryCoproduct Boolean x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). Boolean x a -> Boolean y a -> Boolean (BinaryCoproduct Boolean x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Boolean a1 b1 -> Boolean a2 b2 -> Boolean (BinaryCoproduct Boolean a1 a2) (BinaryCoproduct Boolean b1 b2) Source # | |
HasBinaryCoproducts Unit Source # | In the category of one object that object is its own coproduct. |
Defined in Data.Category.Limit type BinaryCoproduct Unit x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj Unit x -> Obj Unit y -> Unit x (BinaryCoproduct Unit x y) Source # inj2 :: forall (x :: k) (y :: k). Obj Unit x -> Obj Unit y -> Unit y (BinaryCoproduct Unit x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). Unit x a -> Unit y a -> Unit (BinaryCoproduct Unit x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Unit a1 b1 -> Unit a2 b2 -> Unit (BinaryCoproduct Unit a1 a2) (BinaryCoproduct Unit b1 b2) Source # | |
HasBinaryCoproducts (f (Fix f)) => HasBinaryCoproducts (Fix f :: Type -> Type -> Type) Source # |
|
Defined in Data.Category.Fix type BinaryCoproduct (Fix f) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (Fix f) x -> Obj (Fix f) y -> Fix f x (BinaryCoproduct (Fix f) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (Fix f) x -> Obj (Fix f) y -> Fix f y (BinaryCoproduct (Fix f) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). Fix f x a -> Fix f y a -> Fix f (BinaryCoproduct (Fix f) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Fix f a1 b1 -> Fix f a2 b2 -> Fix f (BinaryCoproduct (Fix f) a1 a2) (BinaryCoproduct (Fix f) b1 b2) Source # | |
Ord a => HasBinaryCoproducts (Preorder a :: Type -> Type -> Type) Source # | |
Defined in Data.Category.Preorder type BinaryCoproduct (Preorder a) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (Preorder a) x -> Obj (Preorder a) y -> Preorder a x (BinaryCoproduct (Preorder a) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (Preorder a) x -> Obj (Preorder a) y -> Preorder a y (BinaryCoproduct (Preorder a) x y) Source # (|||) :: forall (x :: k) (a0 :: k) (y :: k). Preorder a x a0 -> Preorder a y a0 -> Preorder a (BinaryCoproduct (Preorder a) x y) a0 Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Preorder a a1 b1 -> Preorder a a2 b2 -> Preorder a (BinaryCoproduct (Preorder a) a1 a2) (BinaryCoproduct (Preorder a) b1 b2) Source # | |
(HasBinaryCoproducts c1, HasBinaryCoproducts c2) => HasBinaryCoproducts (c1 :>>: c2 :: Type -> Type -> TYPE LiftedRep) Source # | |
Defined in Data.Category.Limit type BinaryCoproduct (c1 :>>: c2) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (c1 :>>: c2) x -> Obj (c1 :>>: c2) y -> (c1 :>>: c2) x (BinaryCoproduct (c1 :>>: c2) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (c1 :>>: c2) x -> Obj (c1 :>>: c2) y -> (c1 :>>: c2) y (BinaryCoproduct (c1 :>>: c2) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). (c1 :>>: c2) x a -> (c1 :>>: c2) y a -> (c1 :>>: c2) (BinaryCoproduct (c1 :>>: c2) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). (c1 :>>: c2) a1 b1 -> (c1 :>>: c2) a2 b2 -> (c1 :>>: c2) (BinaryCoproduct (c1 :>>: c2) a1 a2) (BinaryCoproduct (c1 :>>: c2) b1 b2) Source # | |
(Category c, HasBinaryCoproducts d) => HasBinaryCoproducts (Nat c d :: Type -> Type -> Type) Source # | The functor coproduct |
Defined in Data.Category.Limit type BinaryCoproduct (Nat c d) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (Nat c d) x -> Obj (Nat c d) y -> Nat c d x (BinaryCoproduct (Nat c d) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (Nat c d) x -> Obj (Nat c d) y -> Nat c d y (BinaryCoproduct (Nat c d) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). Nat c d x a -> Nat c d y a -> Nat c d (BinaryCoproduct (Nat c d) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Nat c d a1 b1 -> Nat c d a2 b2 -> Nat c d (BinaryCoproduct (Nat c d) a1 a2) (BinaryCoproduct (Nat c d) b1 b2) Source # | |
(HasBinaryCoproducts c1, HasBinaryCoproducts c2) => HasBinaryCoproducts (c1 :**: c2 :: Type -> Type -> Type) Source # | The binary coproduct of the product of 2 categories is the product of their binary coproducts. |
Defined in Data.Category.Limit type BinaryCoproduct (c1 :**: c2) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (c1 :**: c2) x -> Obj (c1 :**: c2) y -> (c1 :**: c2) x (BinaryCoproduct (c1 :**: c2) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (c1 :**: c2) x -> Obj (c1 :**: c2) y -> (c1 :**: c2) y (BinaryCoproduct (c1 :**: c2) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). (c1 :**: c2) x a -> (c1 :**: c2) y a -> (c1 :**: c2) (BinaryCoproduct (c1 :**: c2) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). (c1 :**: c2) a1 b1 -> (c1 :**: c2) a2 b2 -> (c1 :**: c2) (BinaryCoproduct (c1 :**: c2) a1 a2) (BinaryCoproduct (c1 :**: c2) b1 b2) Source # | |
HasBinaryCoproducts (FUN m :: Type -> Type -> Type) Source # | |
Defined in Data.Category.Limit type BinaryCoproduct (FUN m) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (FUN m) x -> Obj (FUN m) y -> FUN m x (BinaryCoproduct (FUN m) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (FUN m) x -> Obj (FUN m) y -> FUN m y (BinaryCoproduct (FUN m) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). FUN m x a -> FUN m y a -> FUN m (BinaryCoproduct (FUN m) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). FUN m a1 b1 -> FUN m a2 b2 -> FUN m (BinaryCoproduct (FUN m) a1 a2) (BinaryCoproduct (FUN m) b1 b2) Source # | |
HasBinaryProducts k2 => HasBinaryCoproducts (Op k2 :: k1 -> k1 -> Type) Source # | Binary products are the dual of binary coproducts. |
Defined in Data.Category.Limit type BinaryCoproduct (Op k2) x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj (Op k2) x -> Obj (Op k2) y -> Op k2 x (BinaryCoproduct (Op k2) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (Op k2) x -> Obj (Op k2) y -> Op k2 y (BinaryCoproduct (Op k2) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). Op k2 x a -> Op k2 y a -> Op k2 (BinaryCoproduct (Op k2) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Op k2 a1 b1 -> Op k2 a2 b2 -> Op k2 (BinaryCoproduct (Op k2) a1 a2) (BinaryCoproduct (Op k2) b1 b2) Source # | |
HasBinaryCoproducts (LTE ('S n)) => HasBinaryCoproducts (LTE ('S ('S n)) :: Fin ('S ('S n)) -> Fin ('S ('S n)) -> Type) Source # | |
Defined in Data.Category.Fin inj1 :: forall (x :: k) (y :: k). Obj (LTE ('S ('S n))) x -> Obj (LTE ('S ('S n))) y -> LTE ('S ('S n)) x (BinaryCoproduct (LTE ('S ('S n))) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (LTE ('S ('S n))) x -> Obj (LTE ('S ('S n))) y -> LTE ('S ('S n)) y (BinaryCoproduct (LTE ('S ('S n))) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). LTE ('S ('S n)) x a -> LTE ('S ('S n)) y a -> LTE ('S ('S n)) (BinaryCoproduct (LTE ('S ('S n))) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). LTE ('S ('S n)) a1 b1 -> LTE ('S ('S n)) a2 b2 -> LTE ('S ('S n)) (BinaryCoproduct (LTE ('S ('S n))) a1 a2) (BinaryCoproduct (LTE ('S ('S n))) b1 b2) Source # | |
HasBinaryCoproducts (LTE ('S 'Z)) Source # | |
Defined in Data.Category.Fin inj1 :: forall (x :: k) (y :: k). Obj (LTE ('S 'Z)) x -> Obj (LTE ('S 'Z)) y -> LTE ('S 'Z) x (BinaryCoproduct (LTE ('S 'Z)) x y) Source # inj2 :: forall (x :: k) (y :: k). Obj (LTE ('S 'Z)) x -> Obj (LTE ('S 'Z)) y -> LTE ('S 'Z) y (BinaryCoproduct (LTE ('S 'Z)) x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). LTE ('S 'Z) x a -> LTE ('S 'Z) y a -> LTE ('S 'Z) (BinaryCoproduct (LTE ('S 'Z)) x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). LTE ('S 'Z) a1 b1 -> LTE ('S 'Z) a2 b2 -> LTE ('S 'Z) (BinaryCoproduct (LTE ('S 'Z)) a1 a2) (BinaryCoproduct (LTE ('S 'Z)) b1 b2) Source # | |
HasBinaryCoproducts Cat Source # | The coproduct of categories |
Defined in Data.Category.Limit type BinaryCoproduct Cat x y :: Kind k Source # inj1 :: forall (x :: k) (y :: k). Obj Cat x -> Obj Cat y -> Cat x (BinaryCoproduct Cat x y) Source # inj2 :: forall (x :: k) (y :: k). Obj Cat x -> Obj Cat y -> Cat y (BinaryCoproduct Cat x y) Source # (|||) :: forall (x :: k) (a :: k) (y :: k). Cat x a -> Cat y a -> Cat (BinaryCoproduct Cat x y) a Source # (+++) :: forall (a1 :: k) (b1 :: k) (a2 :: k) (b2 :: k). Cat a1 b1 -> Cat a2 b2 -> Cat (BinaryCoproduct Cat a1 a2) (BinaryCoproduct Cat b1 b2) Source # |
data CoproductFunctor (k :: Type -> Type -> Type) Source #
Instances
(:+:) :: (Functor p, Functor q, Dom p ~ Dom q, Cod p ~ k, Cod q ~ k, HasBinaryCoproducts k) => p -> q -> p :+: q |
Instances
(Category (Dom p), Category (Cod p)) => Functor (p :+: q) Source # | The coproduct of two functors, passing the same object to both functors and taking the coproduct of the results. |
type Cod (p :+: q) Source # | |
Defined in Data.Category.Limit | |
type Dom (p :+: q) Source # | |
Defined in Data.Category.Limit | |
type (p :+: q) :% a Source # | |
Defined in Data.Category.Limit |
coprodAdj :: HasBinaryCoproducts k => Adjunction k (k :**: k) (CoproductFunctor k) (DiagProd k) Source #
A specialisation of the colimit adjunction to coproducts.
The Either
type represents values with two possibilities: a value of
type
is either Either
a b
or Left
a
.Right
b
The Either
type is sometimes used to represent a value which is
either correct or an error; by convention, the Left
constructor is
used to hold an error value and the Right
constructor is used to
hold a correct value (mnemonic: "right" also means "correct").
Examples
The type
is the type of values which can be either
a Either
String
Int
String
or an Int
. The Left
constructor can be used only on
String
s, and the Right
constructor can be used only on Int
s:
>>>
let s = Left "foo" :: Either String Int
>>>
s
Left "foo">>>
let n = Right 3 :: Either String Int
>>>
n
Right 3>>>
:type s
s :: Either String Int>>>
:type n
n :: Either String Int
The fmap
from our Functor
instance will ignore Left
values, but
will apply the supplied function to values contained in a Right
:
>>>
let s = Left "foo" :: Either String Int
>>>
let n = Right 3 :: Either String Int
>>>
fmap (*2) s
Left "foo">>>
fmap (*2) n
Right 6
The Monad
instance for Either
allows us to chain together multiple
actions which may fail, and fail overall if any of the individual
steps failed. First we'll write a function that can either parse an
Int
from a Char
, or fail.
>>>
import Data.Char ( digitToInt, isDigit )
>>>
:{
let parseEither :: Char -> Either String Int parseEither c | isDigit c = Right (digitToInt c) | otherwise = Left "parse error">>>
:}
The following should work, since both '1'
and '2'
can be
parsed as Int
s.
>>>
:{
let parseMultiple :: Either String Int parseMultiple = do x <- parseEither '1' y <- parseEither '2' return (x + y)>>>
:}
>>>
parseMultiple
Right 3
But the following should fail overall, since the first operation where
we attempt to parse 'm'
as an Int
will fail:
>>>
:{
let parseMultiple :: Either String Int parseMultiple = do x <- parseEither 'm' y <- parseEither '2' return (x + y)>>>
:}
>>>
parseMultiple
Left "parse error"
Instances
Foldable (Either a) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Either a m -> m # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # toList :: Either a a0 -> [a0] # length :: Either a a0 -> Int # elem :: Eq a0 => a0 -> Either a a0 -> Bool # maximum :: Ord a0 => Either a a0 -> a0 # minimum :: Ord a0 => Either a a0 -> a0 # | |
Traversable (Either a) | Since: base-4.7.0.0 |
Applicative (Either e) | Since: base-3.0 |
Functor (Either a) | Since: base-3.0 |
Monad (Either e) | Since: base-4.4.0.0 |
Semigroup (Either a b) | Since: base-4.9.0.0 |
(Read a, Read b) => Read (Either a b) | Since: base-3.0 |
(Show a, Show b) => Show (Either a b) | Since: base-3.0 |
(Eq a, Eq b) => Eq (Either a b) | Since: base-2.1 |
(Ord a, Ord b) => Ord (Either a b) | Since: base-2.1 |