27 lines
802 B
Haskell
27 lines
802 B
Haskell
module Relation.Product where
|
|
|
|
import Relation.Base
|
|
import Relation.Reflexive
|
|
import Relation.Transitive
|
|
|
|
type Pi1 :: (i, j) -> i
|
|
type family Pi1 xy where
|
|
Pi1 '(x, _) = x
|
|
type Pi2 :: (i, j) -> j
|
|
type family Pi2 xy where
|
|
Pi2 '(_, y) = y
|
|
|
|
-- | A product of categories.
|
|
type ProductRel :: Relation j -> Relation k -> Relation (j, k)
|
|
data ProductRel r s x y = Product (r (Pi1 x) (Pi1 y)) (s (Pi2 x) (Pi2 y))
|
|
|
|
instance (Reflexive r, Reflexive s) => Reflexive (ProductRel r s) where
|
|
idL (Product f g) = Product (idL f) (idL g)
|
|
idR (Product f g) = Product (idR f) (idR g)
|
|
|
|
instance (Wide r, Wide s) => Wide (ProductRel r s) where
|
|
id = Product id id
|
|
|
|
instance (Transitive r, Transitive s) => Transitive (ProductRel r s) where
|
|
Product g1 g2 . Product f1 f2 = Product (g1 . f1) (g2 . f2)
|