Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created March 19, 2019 21:52
Show Gist options
  • Save dmwit/a09f1535e499c5a8a675795bee8e75fb to your computer and use it in GitHub Desktop.
Save dmwit/a09f1535e499c5a8a675795bee8e75fb to your computer and use it in GitHub Desktop.
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
import GHC.Exts
type family AllAllowed k xs where
AllAllowed k '[] = ()
AllAllowed k (x : xs) = (Allowed k x, AllAllowed k xs)
class Category k where
type Allowed k a :: Constraint
type Allowed k a = ()
id :: Allowed k a => k a a
(.) :: AllAllowed k [a,b,c] => k b c -> k a b -> k a c
class (Category k, forall a b. (Allowed k a, Allowed k b) => Allowed k (a, b)) => Monoidal k where
x :: AllAllowed k [a,b,c,d] => k a c -> k b d -> k (a,b) (c,d)
instance Category (->) where
id = \x -> x
f . g = \x -> f (g x)
instance Monoidal (->) where
x f g (a,b) = (f a, g b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment