{-# LANGUAGE TypeOperators #-}
infix 9 ∘
class Category k where
ident :: a `k` a
(∘) :: (b `k` c) -> (a `k` b) -> (a `k` c)
instance Category (->) where
ident = \x -> x
g ∘ f = \x -> g (f x)
infix 3 Δ
class Category k => Cartesian k where
(Δ) :: (a `k` c) -> (a `k` d) -> (a `k` (c,d)))
instance Category (->) where
ident = \x -> x
g ∘ f = \x -> g (f x)
sq x = x * x
main = print $
-- ident sq 2
(sq ∘ sq) 2
Last active
December 4, 2018 11:46
-
-
Save witt3rd/643501ee8c35eb782a2400b00c9f33f0 to your computer and use it in GitHub Desktop.
Categories in Haskell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment