Created
April 1, 2019 14:03
-
-
Save oisdk/d0d63bd7f6fe9f17d5d318b733b29298 to your computer and use it in GitHub Desktop.
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 RankNTypes #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE PolyKinds #-} | |
import Prelude hiding ((.), id, Functor) | |
import Data.Constraint | |
import Data.Kind | |
class Category (cat :: k -> k -> Type) where | |
type Domain cat (x :: k) :: Constraint | |
id :: Domain cat a => cat a a | |
(.) :: (Domain cat a, Domain cat b, Domain cat c) | |
=> cat b c | |
-> cat a b | |
-> cat a c | |
newtype Functor (c :: k -> k -> Type) (c' :: k -> k -> Type) = Functor { runFunctor :: forall a b. c a b -> c' a b } | |
instance Category (->) where | |
type Domain (->) a = () | |
id = \x -> x | |
f . g = \x -> f (g x) | |
instance Category Functor where | |
type Domain Functor c = Category c | |
id = Functor (\x -> x) | |
Functor f . Functor g = Functor (\x -> f (g x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment