Created
July 14, 2023 16:58
-
-
Save sjoerdvisscher/db39e5cc3f6ead4c55c5491f0f68cdd6 to your computer and use it in GitHub Desktop.
Confluence? Oh, you mean a distributive law between Promonads! https://elk.zone/types.pl/@totbwf/110712999795376253
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, TypeOperators #-} | |
import Data.Profunctor | |
data Exists2 f g where | |
Exists2 :: f x -> g x -> Exists2 f g | |
data Confluence p = Confluence (forall a b c. (p a b, p a c) -> Exists2 (p b) (p c)) | |
newtype Op p a b = Op { runOp :: p b a } | |
type p ~~> q = forall a b. p a b -> q a b | |
data Procompose p q b c where | |
Procompose :: p x c -> q b x -> Procompose p q b c | |
type Dist p q = Procompose p q ~~> Procompose q p | |
dist :: Confluence p -> Dist p (Op p) | |
dist (Confluence c) (Procompose pac (Op pab)) = case c (pab, pac) of Exists2 pbd pcd -> Procompose (Op pcd) pbd | |
conf :: Dist p (Op p) -> Confluence p | |
conf dist = Confluence (\(pab, pac) -> case dist (Procompose pab (Op pac)) of Procompose (Op pbd) pcd -> Exists2 pbd pcd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment