Last active
June 9, 2023 21:58
-
-
Save LSLeary/0d3bf054f73c08910a6da2cfb49a4c28 to your computer and use it in GitHub Desktop.
Parametrickery: Subtyping & Monotonicity
This file contains hidden or 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 DataKinds #-} | |
module Sub where | |
data Sub = S Sub | |
data Three (s :: Sub) a b c where | |
One :: a -> Three s a b c | |
Two :: b -> Three (S s ) a b c | |
Three :: c -> Three (S (S s)) a b c | |
type LtEqOne a b c = forall s. Three s a b c | |
type LtEqTwo a b c = forall s. Three (S s ) a b c | |
type LtEqThree a b c = forall s. Three (S (S s)) a b c | |
-- Note that, similar to MonoMaybe, functions parametric in s: | |
-- | |
-- forall s. Three s a b c -> Three s d e f | |
-- | |
-- are monotonically decreasing. | |
-- | |
-- Further, we obtain the subtyping relation: | |
-- | |
-- LtEqOne a b c <: LtEqTwo a b c <: LtEqThree a b c | |
-- | |
-- as evidenced below. | |
oneLtTwo :: LtEqOne a b c -> LtEqTwo a b c | |
oneLtTwo x = x | |
twoLtThree :: LtEqTwo a b c -> LtEqThree a b c | |
twoLtThree x = x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment