Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created August 3, 2023 09:36
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 Lysxia/e43ac83dbd48dc4ff83b83c54c8ac59a to your computer and use it in GitHub Desktop.
Save Lysxia/e43ac83dbd48dc4ff83b83c54c8ac59a to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes, GADTs #-}
module O where
data Coyoneda g a where
Coyoneda :: forall g a x. g x -> (x -> a) -> Coyoneda g a
newtype Obj f g = Obj { unObj :: forall a. f a -> Coyoneda g (a, Obj f g) }
compose :: Obj f g -> Obj g h -> Obj f h
compose (Obj a) (Obj b) = Obj (\f ->
case a f of
Coyoneda g k -> case b g of
Coyoneda h l -> Coyoneda h (kcompose l k))
kcompose :: (y -> (x, Obj g h)) -> (x -> (z, Obj f g)) -> (y -> (z, Obj f h))
kcompose l k y =
let (x, b) = l y
(z, a) = k x in (z, compose a b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment