-
-
Save Lysxia/e43ac83dbd48dc4ff83b83c54c8ac59a 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, 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