0 | module Test.DepTyCheck.Gen.Emptiness
2 | import Control.Relation
5 | import public Language.Implicits.IfUnsolved
12 | data Emptiness = NonEmpty | MaybeEmpty
16 | NonEmpty == NonEmpty = True
17 | MaybeEmpty == MaybeEmpty = True
18 | NonEmpty == MaybeEmpty = False
19 | MaybeEmpty == NonEmpty = False
24 | data NoWeaker : (from, to : Emptiness) -> Type where
25 | NN : NonEmpty `NoWeaker` NonEmpty
26 | AS : em `NoWeaker` MaybeEmpty
28 | export infix 6 `NoWeaker`
30 | Uninhabited (MaybeEmpty `NoWeaker` NonEmpty) where
31 | uninhabited _ impossible
36 | compare MaybeEmpty NonEmpty = LT
37 | compare NonEmpty MaybeEmpty = GT
41 | Reflexive _ NoWeaker where
42 | reflexive {x=NonEmpty} = %search
43 | reflexive {x=MaybeEmpty} = %search
46 | transitive' : x `NoWeaker` y -> y `NoWeaker` z -> x `NoWeaker` z
47 | transitive' NN NN = %search
48 | transitive' NN AS = %search
49 | transitive' AS AS = %search
52 | Transitive _ NoWeaker where
53 | transitive = transitive'
56 | Antisymmetric _ NoWeaker where
57 | antisymmetric NN NN = Refl
58 | antisymmetric AS AS = Refl
61 | Preorder _ NoWeaker where
64 | PartialOrder _ NoWeaker where
67 | Connex _ NoWeaker where
68 | connex {x=NonEmpty} {y=NonEmpty} = %search
69 | connex {x=MaybeEmpty} {y=MaybeEmpty} = %search
70 | connex {x=NonEmpty} {y=MaybeEmpty} = %search
71 | connex {x=MaybeEmpty} {y=NonEmpty} = %search
74 | LinearOrder _ NoWeaker where
77 | StronglyConnex _ NoWeaker where
78 | order NonEmpty NonEmpty = %search
79 | order NonEmpty MaybeEmpty = %search
80 | order MaybeEmpty NonEmpty = %search
81 | order MaybeEmpty MaybeEmpty = %search
84 | rev : {a, b : _} -> Not (a `NoWeaker` b) -> b `NoWeaker` a
85 | rev f = either (absurd . f) id $
order a b
88 | nonEmptyIsStrongest : {em : _} -> NonEmpty `NoWeaker` em
89 | nonEmptyIsStrongest {em=NonEmpty} = NN
90 | nonEmptyIsStrongest {em=MaybeEmpty} = AS
93 | maybeEmptyIsMinimal : (0 _ : MaybeEmpty `NoWeaker` em) -> em = MaybeEmpty
94 | maybeEmptyIsMinimal nw = irrelevantEq $
case nw of AS => Refl
97 | nonEmptyIsMaximal : (0 _ : em `NoWeaker` NonEmpty) -> em = NonEmpty
98 | nonEmptyIsMaximal nw = irrelevantEq $
case nw of NN => Refl
101 | minMaybeEmptyLeft : (0 em : Emptiness) -> min MaybeEmpty em = MaybeEmpty
102 | minMaybeEmptyLeft em = irrelevantEq $
case em of
107 | minMaybeEmptyRight : (0 em : Emptiness) -> min em MaybeEmpty = MaybeEmpty
108 | minMaybeEmptyRight em = irrelevantEq $
case em of
113 | minNonEmptyLeft : (0 em : Emptiness) -> min NonEmpty em = em
114 | minNonEmptyLeft em = irrelevantEq $
case em of
119 | minNonEmptyRight : (0 em : Emptiness) -> min em NonEmpty = em
120 | minNonEmptyRight em = irrelevantEq $
case em of
125 | minSame : (0 em : Emptiness) -> min em em = em
126 | minSame em = irrelevantEq $
case em of
131 | minNoWeaker : a1 `NoWeaker` a2 -> b1 `NoWeaker` b2 ->
132 | min a1 b1 `NoWeaker` min a2 b2
133 | minNoWeaker NN nw = rewrite minNonEmptyLeft b1 in
134 | rewrite minNonEmptyLeft b2 in
136 | minNoWeaker AS _ = rewrite minMaybeEmptyLeft b2 in AS
139 | minNoWeakerLeft : {c : _} -> a `NoWeaker` b -> min a c `NoWeaker` min b c
140 | minNoWeakerLeft nw = minNoWeaker nw reflexive
143 | minNoWeakerRight : {c : _} -> a `NoWeaker` b -> min c a `NoWeaker` min c b
144 | minNoWeakerRight nw = minNoWeaker reflexive nw
147 | leftNoWeakerMin : {a, b : _} -> a `NoWeaker` min a b
148 | leftNoWeakerMin {a=NonEmpty} = nonEmptyIsStrongest
149 | leftNoWeakerMin {a=MaybeEmpty} = rewrite minMaybeEmptyLeft b in reflexive
152 | rightNoWeakerMin : {a, b : _} -> b `NoWeaker` min a b
153 | rightNoWeakerMin {b=NonEmpty} = nonEmptyIsStrongest
154 | rightNoWeakerMin {b=MaybeEmpty} = rewrite minMaybeEmptyRight a in reflexive
157 | noWeakerReflexive : {em : _} -> em `NoWeaker` em
158 | noWeakerReflexive = reflexive