Skip to content

Commit

Permalink
inline always
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Oct 6, 2023
1 parent 9970a3f commit f776f7f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Stdlib/Data/Int.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import Stdlib.Data.Int.Ord as Int;
builtin int-to-string
axiom intToString : Int -> String;

{-# inline: true #-}
{-# specialize: true, inline: always #-}
instance
eqIntI : Eq Int := mkEq (Int.==);

{-# inline: true #-}
{-# specialize: true, inline: always #-}
instance
ordIntI : Ord Int := mkOrd Int.compare;

instance
showIntI : Show Int := mkShow intToString;

{-# specialize: true, inline: true #-}
{-# specialize: true, inline: always #-}
instance
naturalIntI : Natural Int :=
mkNatural@{
Expand All @@ -42,7 +42,7 @@ naturalIntI : Natural Int :=
fromNat := ofNat;
};

{-# specialize: true, inline: true #-}
{-# specialize: true, inline: always #-}
instance
integralIntI : Integral Int :=
mkIntegral@{
Expand Down
6 changes: 3 additions & 3 deletions Stdlib/Data/Nat.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ axiom natToString : Nat -> String;
builtin string-to-nat
axiom stringToNat : String -> Nat;

{-# inline: true #-}
{-# specialize: true, inline: always #-}
instance
eqNatI : Eq Nat := mkEq (Nat.==);

{-# inline: true #-}
{-# specialize: true, inline: always #-}
instance
ordNatI : Ord Nat := mkOrd Nat.compare;

instance
showNatI : Show Nat := mkShow natToString;

{-# specialize: true, inline: true #-}
{-# specialize: true, inline: always #-}
instance
naturalNatI : Natural Nat :=
mkNatural@{
Expand Down
6 changes: 3 additions & 3 deletions Stdlib/Trait/Eq.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ trait
type Eq A := mkEq {eq : A -> A -> Bool};

syntax operator == comparison;
syntax operator /= comparison;

{-# inline: always #-}
== {A} {{Eq A}} : A -> A -> Bool := Eq.eq;

syntax operator /= comparison;

--- Tests for inequality.
{-# inline: true #-}
{-# inline: always #-}
/= {A} {{Eq A}} (x y : A) : Bool := not (x == y);
7 changes: 5 additions & 2 deletions Stdlib/Trait/Natural.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ type Natural A :=

open Natural using {div; mod} public;

syntax operator + additive;
syntax operator * multiplicative;

-- TODO: we need to define those separately because it's currently not possible
-- to declare record fields as operators
syntax operator + additive;
{-# inline: always #-}
+ {A} {{Natural A}} : A -> A -> A := Natural.+;

syntax operator * multiplicative;
{-# inline: always #-}
* {A} {{Natural A}} : A -> A -> A := Natural.*;
6 changes: 6 additions & 0 deletions Stdlib/Trait/Ord.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Ord A := mkOrd {cmp : A -> A -> Ordering};
syntax operator <= comparison;

--- Returns ;true; iff the first element is less than or equal to the second.
{-# inline: always #-}
<= {A} {{Ord A}} (x y : A) : Bool :=
case Ord.cmp x y of {
| EQ := true
Expand All @@ -38,6 +39,7 @@ syntax operator <= comparison;
syntax operator < comparison;

--- Returns ;true; iff the first element is less than the second.
{-# inline: always #-}
< {A} {{Ord A}} (x y : A) : Bool :=
case Ord.cmp x y of {
| EQ := false
Expand All @@ -48,15 +50,19 @@ syntax operator < comparison;
syntax operator > comparison;

--- Returns ;true; iff the first element is greater than the second.
{-# inline: always #-}
> {A} {{Ord A}} (x y : A) : Bool := y < x;

syntax operator >= comparison;

--- Returns ;true; iff the first element is greater than or equal to the second.
{-# inline: always #-}
>= {A} {{Ord A}} (x y : A) : Bool := y <= x;

--- Returns the smaller element.
{-# inline: always #-}
min {A} {{Ord A}} (x y : A) : A := if (x < y) x y;

--- Returns the larger element.
{-# inline: always #-}
max {A} {{Ord A}} (x y : A) : A := if (x > y) x y;

0 comments on commit f776f7f

Please sign in to comment.