0 | module Data.Prim.String
2 | import public Control.Order
3 | import public Control.Relation
4 | import public Control.Relation.ReflexiveClosure
5 | import public Control.Relation.Trichotomy
6 | import public Data.Maybe0
10 | unsafeRefl : a === b
11 | unsafeRefl = believe_me (Builtin.Refl {x = a})
19 | data (<) : (m,n : String) -> Type where
20 | LT : {0 m,n : String} -> (0 prf : (m < n) === True) -> m < n
26 | 0 mkLT : (0 prf : (m < n) === True) -> m < n
33 | 0 runLT : m < n -> (m < n) === True
34 | runLT (LT prf) = prf
39 | strictLT : (0 p : m < n) -> Lazy c -> c
40 | strictLT (LT prf) x = x
48 | 0 (>) : (m,n : String) -> Type
53 | 0 (<=) : (m,n : String) -> Type
54 | (<=) = ReflexiveClosure (<)
60 | 0 ltNotEQ : m < n -> Not (m === n)
61 | ltNotEQ x = strictLT x $
assert_total (idris_crash "IMPOSSIBLE: LT and EQ")
63 | 0 ltNotGT : m < n -> Not (n < m)
64 | ltNotGT x = strictLT x $
assert_total (idris_crash "IMPOSSIBLE: LT and GT")
66 | 0 eqNotLT : m === n -> Not (m < n)
67 | eqNotLT = flip ltNotEQ
69 | public export %inline
70 | lt : (x,y : String) -> Maybe0 (x < y)
71 | lt x y = case prim__lt_String x y of
73 | _ => Just0 (mkLT unsafeRefl)
75 | public export %inline
76 | lte : (x,y : String) -> Maybe0 (x <= y)
77 | lte x y = case prim__lte_String x y of
79 | _ => Just0 (if x < y then (Rel $
mkLT unsafeRefl) else (fromEq unsafeRefl))
82 | comp : (m,n : String) -> Trichotomy (<) m n
83 | comp m n = case prim__lt_String m n of
84 | 0 => case prim__eq_String m n of
85 | 0 => GT (ltNotGT $
LT unsafeRefl) (ltNotEQ $
LT unsafeRefl) (LT unsafeRefl)
86 | x => EQ (eqNotLT unsafeRefl) (unsafeRefl) (eqNotLT unsafeRefl)
87 | x => LT (LT unsafeRefl) (ltNotEQ $
LT unsafeRefl) (ltNotGT $
LT unsafeRefl)
94 | Transitive String (<) where
95 | transitive _ _ = LT unsafeRefl
98 | Trichotomous String (<) where
99 | trichotomy m n = comp m n
112 | 0 GTE_MinString : (m : String) -> MinString <= m
113 | GTE_MinString m = case comp MinString m of
114 | LT x f g => %search
115 | EQ f x g => fromEq x
116 | GT f g x => assert_total $
idris_crash #"IMPOSSIBLE: String smaller than """#
120 | 0 Not_LT_MinString : m < MinString -> Void
121 | Not_LT_MinString p = Not_LT_and_GTE p (GTE_MinString m)