Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created April 1, 2019 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oisdk/d0d63bd7f6fe9f17d5d318b733b29298 to your computer and use it in GitHub Desktop.
Save oisdk/d0d63bd7f6fe9f17d5d318b733b29298 to your computer and use it in GitHub Desktop.
{-# 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