diff --git a/Stdlib/Data/Bool.juvix b/Stdlib/Data/Bool.juvix index 6b275e43..af191c98 100644 --- a/Stdlib/Data/Bool.juvix +++ b/Stdlib/Data/Bool.juvix @@ -12,16 +12,8 @@ deriving instance eqBoolI : Eq Bool; {-# specialize: true, inline: case #-} -instance -ordBoolI : Ord Bool := - mkOrd@{ - cmp (x y : Bool) : Ordering := - case x, y of - | false, false := Equal - | false, true := LessThan - | true, false := GreaterThan - | true, true := Equal; - }; +deriving instance +ordBoolI : Ord Bool; instance showBoolI : Show Bool := diff --git a/Stdlib/Data/Maybe.juvix b/Stdlib/Data/Maybe.juvix index 25103e62..f2fe5036 100644 --- a/Stdlib/Data/Maybe.juvix +++ b/Stdlib/Data/Maybe.juvix @@ -27,16 +27,8 @@ showMaybeI {A} {{Show A}} : Show (Maybe A) := }; {-# specialize: true, inline: case #-} -instance -ordMaybeI {A} {{Ord A}} : Ord (Maybe A) := - mkOrd@{ - cmp (m1 m2 : Maybe A) : Ordering := - case m1, m2 of - | nothing, nothing := Equal - | just a1, just a2 := Ord.cmp a1 a2 - | nothing, just _ := LessThan - | just _, nothing := GreaterThan; - }; +deriving instance +ordMaybeI {A} {{Ord A}} : Ord (Maybe A); {-# specialize: true, inline: case #-} instance diff --git a/Stdlib/Data/Pair.juvix b/Stdlib/Data/Pair.juvix index fcf6a17e..76fdd832 100644 --- a/Stdlib/Data/Pair.juvix +++ b/Stdlib/Data/Pair.juvix @@ -13,18 +13,8 @@ deriving instance eqProductI {A B} {{Eq A}} {{Eq B}} : Eq (Pair A B); {-# specialize: true, inline: case #-} -instance -ordProductI {A B} : {{Ord A}} -> {{Ord B}} -> Ord (Pair A B) - | {{mkOrd cmpA}} {{mkOrd cmpB}} := - mkOrd@{ - cmp (p1 p2 : Pair A B) : Ordering := - case p1, p2 of - (a1, b1), a2, b2 := - case cmpA a1 a2 of - | LessThan := LessThan - | GreaterThan := GreaterThan - | Equal := cmpB b1 b2; - }; +deriving instance +ordProductI {A B} : {{Ord A}} -> {{Ord B}} -> Ord (Pair A B); instance showProductI {A B} : {{Show A}} -> {{Show B}} -> Show (Pair A B) diff --git a/Stdlib/Data/Result.juvix b/Stdlib/Data/Result.juvix index a836b286..2f6245ad 100644 --- a/Stdlib/Data/Result.juvix +++ b/Stdlib/Data/Result.juvix @@ -11,17 +11,9 @@ import Stdlib.Trait.Show open; import Stdlib.Trait open; {-# specialize: true, inline: case #-} -instance +deriving instance ordResultI - {Error Value} {{Ord Error}} {{Ord Value}} : Ord (Result Error Value) := - mkOrd@{ - cmp (result1 result2 : Result Error Value) : Ordering := - case result1, result2 of - | error a1, error a2 := Ord.cmp a1 a2 - | ok b1, ok b2 := Ord.cmp b1 b2 - | error _, ok _ := LessThan - | ok _, error _ := GreaterThan; - }; + {Error Value} {{Ord Error}} {{Ord Value}} : Ord (Result Error Value); {-# specialize: true, inline: case #-} deriving instance diff --git a/Stdlib/Data/Unit.juvix b/Stdlib/Data/Unit.juvix index a719b592..c004f780 100644 --- a/Stdlib/Data/Unit.juvix +++ b/Stdlib/Data/Unit.juvix @@ -13,11 +13,8 @@ import Stdlib.Trait.Foldable open; deriving instance eqUnitI : Eq Unit; -instance -ordUnitI : Ord Unit := - mkOrd@{ - cmp (_ _ : Unit) : Ordering := Equal; - }; +deriving instance +ordUnitI : Ord Unit; instance showUnitI : Show Unit := diff --git a/Stdlib/Trait/Ord.juvix b/Stdlib/Trait/Ord.juvix index c55ab9e8..d1222b6e 100644 --- a/Stdlib/Trait/Ord.juvix +++ b/Stdlib/Trait/Ord.juvix @@ -4,6 +4,7 @@ import Stdlib.Data.Fixity open; import Stdlib.Data.Bool.Base open; import Stdlib.Trait.Eq open; +builtin ordering type Ordering := | LessThan | Equal @@ -28,8 +29,12 @@ deriving instance orderingEqI : Eq Ordering; --- A trait for defining a total order +builtin ord trait -type Ord A := mkOrd@{cmp : A -> A -> Ordering}; +type Ord A := mkOrd@{builtin compare cmp : A -> A -> Ordering}; + +deriving instance +orderingOrdI : Ord Ordering; syntax operator <= comparison;