Last active
December 18, 2015 00:09
-
-
Save thoughtpolice/5695063 to your computer and use it in GitHub Desktop.
Kind-polymorphic Category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE PolyKinds, KindSignatures, TypeOperators, TypeFamilies #-} | |
{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes #-} | |
module Categories where | |
import qualified Prelude | |
import GHC.Prim (Constraint) | |
-------------------------------------------------------------------------------- | |
-- Kind-polymorphic Category | |
class Category cat where | |
-- inferred: 'cat :: k -> k -> *' | |
id :: cat a a | |
(.) :: cat b c -> cat a b -> cat a c | |
instance Category (->) where | |
id = Prelude.id | |
(.) = (Prelude..) | |
-------------------------------------------------------------------------------- | |
-- Logical entailment | |
data Dict :: Constraint -> * where | |
Dict :: ctx => Dict ctx | |
newtype (|-) a b = Sub (a => Dict b) | |
(\\) :: a => (b => r) -> (a |- b) -> r | |
r \\ Sub Dict = r | |
reflexive :: a |- a | |
reflexive = Sub Dict | |
transitive :: (b |- c) -> (a |- b) -> (a |- c) | |
transitive f g = Sub (Dict \\ f \\ g) | |
instance Category (|-) where | |
id = reflexive | |
(.) = transitive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment