Skip to content

Commit

Permalink
pragmas
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Aug 12, 2024
1 parent a0904ae commit 2d3cb8e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Stdlib/Data/Bool.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Stdlib.Trait.Eq open;
import Stdlib.Trait.Ord open;
import Stdlib.Trait.Show open;

{-# specialize: true, inline: case #-}
instance
boolEqI : Eq Bool :=
mkEq
Expand All @@ -14,6 +15,7 @@ boolEqI : Eq Bool :=
| _ _ := false
};

{-# specialize: true, inline: case #-}
instance
boolOrdI : Ord Bool :=
mkOrd
Expand Down
8 changes: 4 additions & 4 deletions Stdlib/Data/List.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ showListI {A} {{Show A}} : Show (List A) :=
| s := "(" ++str go s ++str ")"
};

{-# inline: case #-}
{-# specialize: true, inline: case #-}
instance
functorListI : Functor List :=
mkFunctor@{
map := listMap
};

{-# specialize: true, inline: case #-}
{-# specialize: true, inline: true #-}
instance
monomorphicFunctorListI {A} : Monomorphic.Functor (List A) A := fromPolymorphicFunctor;

{-# inline: case #-}
{-# specialize: true, inline: case #-}
instance
polymorphicFoldableListI : Polymorphic.Foldable List :=
Polymorphic.mkFoldable@{
for := listFor;
rfor := listRfor
};

{-# specialize: true, inline: case #-}
{-# specialize: true, inline: true #-}
instance
foldableListI {A} : Foldable (List A) A := fromPolymorphicFoldable;
5 changes: 4 additions & 1 deletion Stdlib/Data/Maybe.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Stdlib.Trait.Functor open;
import Stdlib.Data.Bool.Base open;
import Stdlib.Data.String.Base open;

{-# specialize: true, inline: case #-}
instance
eqMaybeI {A} {{Eq A}} : Eq (Maybe A) :=
mkEq
Expand All @@ -27,6 +28,7 @@ showMaybeI {A} {{Show A}} : Show (Maybe A) :=
| (just a) := "just " ++str Show.show a
};

{-# specialize: true, inline: case #-}
instance
ordMaybeI {A} {{Ord A}} : Ord (Maybe A) :=
mkOrd
Expand All @@ -37,6 +39,7 @@ ordMaybeI {A} {{Ord A}} : Ord (Maybe A) :=
| (just _) nothing := GT
};

{-# specialize: true, inline: case #-}
instance
functorMaybeI : Functor Maybe :=
mkFunctor@{
Expand All @@ -45,6 +48,6 @@ functorMaybeI : Functor Maybe :=
| (just a) := just (f a)
};

{-# specialize: true, inline: case #-}
{-# specizalize: true, inline: true #-}
instance
monomorphicFunctorMaybeI {A} : Monomorphic.Functor (Maybe A) A := fromPolymorphicFunctor;
2 changes: 2 additions & 0 deletions Stdlib/Data/Pair.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import Stdlib.Trait.Eq open;
import Stdlib.Trait.Ord open;
import Stdlib.Trait.Show open;

{-# specialize: true, inline: case #-}
instance
eqProductI {A B} : {{Eq A}} -> {{Eq B}} -> Eq (Pair A B)
| {{mkEq eq-a}} {{mkEq eq-b}} := mkEq λ {(a1, b1) (a2, b2) := eq-a a1 a2 && eq-b b1 b2};

{-# specialize: true, inline: case #-}
instance
ordProductI {A B} : {{Ord A}} -> {{Ord B}} -> Ord (Pair A B)
| {{mkOrd cmp-a}} {{mkOrd cmp-b}} :=
Expand Down
4 changes: 4 additions & 0 deletions Stdlib/Data/Result.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Stdlib.Trait.Eq open;
import Stdlib.Trait.Ord open;
import Stdlib.Trait.Functor open;

{-# specialize: true, inline: case #-}
instance
ordResultI {A B} {{Ord A}} {{Ord B}} : Ord (Result A B) :=
mkOrd@{
Expand All @@ -17,6 +18,7 @@ ordResultI {A B} {{Ord A}} {{Ord B}} : Ord (Result A B) :=
| (ok _) (error _) := GT
};

{-# specialize: true, inline: case #-}
instance
eqResultI {A B} {{Eq A}} {{Eq B}} : Eq (Result A B) :=
mkEq@{
Expand All @@ -26,12 +28,14 @@ eqResultI {A B} {{Eq A}} {{Eq B}} : Eq (Result A B) :=
| _ _ := false
};

{-# specialize: true, inline: case #-}
instance
functorResultI {err} : Functor (Result err) :=
mkFunctor@{
map := mapOk
};

{-# specialize: true, inline: true #-}
instance
monomorphicFunctorResultI {err res} : Monomorphic.Functor (Result err res) res :=
fromPolymorphicFunctor;
3 changes: 3 additions & 0 deletions Stdlib/Data/Unit.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ ordUnitI : Ord Unit := mkOrd λ {unit unit := EQ};
instance
showUnitI : Show Unit := mkShow λ {unit := "unit"};

{-# specialize: true, inline: case #-}
instance
foldableUnitI : Foldable Unit Unit :=
mkFoldable@{
{-# inline: true #-}
rfor {B : Type} (f : B -> Unit -> B) (ini : B) (_ : Unit) : B := f ini unit;
{-# inline: true #-}
for {B : Type} (f : B -> Unit -> B) (ini : B) (_ : Unit) : B := f ini unit
};
5 changes: 3 additions & 2 deletions Stdlib/Trait/Foldable/Monomorphic.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Stdlib.Function open;
import Stdlib.Trait.Foldable.Polymorphic as Poly;

--- A trait for combining elements into a single result, processing one element at a time.
{-# specialize: true #-}
trait
type Foldable (container elem : Type) :=
mkFoldable {
Expand All @@ -26,7 +27,7 @@ fromPolymorphicFoldable
rfor := Poly.rfor
};

{-# inline: 2 #-}
{-# inline: true #-}
foldl
{container elem}
{{Foldable container elem}}
Expand All @@ -37,7 +38,7 @@ foldl
: B := for (acc := ini) (x in ls) {g acc x};

--- Combine the elements of the type using the provided function starting with the element in the right-most position.
{-# inline: 1 #-}
{-# inline: 2 #-}
foldr
{container elem : Type}
{{Foldable container elem}}
Expand Down
5 changes: 5 additions & 0 deletions Stdlib/Trait/Functor/Monomorphic.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ import Stdlib.Data.Fixity open;
import Stdlib.Data.Unit open;
import Stdlib.Trait.Functor.Polymorphic as Poly;

{-# specialize: true #-}
trait
type Functor (container elem : Type) :=
mkFunctor {
syntax iterator map {init := 0; range := 1};
{-# specialize: [1] #-}
map : (elem -> elem) -> container -> container
};

open Functor public;

{-# inline: case #-}
fromPolymorphicFunctor {f : Type -> Type} {{Poly.Functor f}} {elem} : Functor (f elem) elem :=
mkFunctor@{
map := Poly.map
};

syntax operator <$> lapp;
{-# inline: true #-}
<$> {container elem} {{Functor container elem}} : (elem -> elem) -> container -> container := map;

syntax operator $> lapp;
{-# inline: true #-}
$> {container elem : Type} {{Functor container elem}} (fa : container) (b : elem) : container :=
λ {_ := b} <$> fa;
5 changes: 5 additions & 0 deletions Stdlib/Trait/Functor/Polymorphic.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ module Stdlib.Trait.Functor.Polymorphic;
import Stdlib.Data.Fixity open;
import Stdlib.Data.Unit open;

{-# specialize: true #-}
trait
type Functor (f : Type -> Type) :=
mkFunctor {
syntax iterator map {init := 0; range := 1};
{-# specialize: [1] #-}
map : {A B : Type} -> (A -> B) -> f A -> f B
};

open Functor public;

syntax operator <$> lapp;
{-# inline: true #-}
<$> {f : Type -> Type} {{Functor f}} {A B} : (A -> B) -> f A -> f B := map;

syntax operator $> lapp;
{-# inline: true #-}
$> {f : Type → Type} {A B : Type} {{Functor f}} (fa : f A) (b : B) : f B := λ {_ := b} <$> fa;

{-# inline: true #-}
void {f : Type → Type} {A : Type} {{Functor f}} (fa : f A) : f Unit := fa $> unit;

0 comments on commit 2d3cb8e

Please sign in to comment.