Skip to content

Commit

Permalink
New Iterator/Fixity record syntax (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored Sep 14, 2023
1 parent f9ebce1 commit 4facf14
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
26 changes: 13 additions & 13 deletions Stdlib/Data/Fixity.juvix
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module Stdlib.Data.Fixity;

syntax fixity rapp {arity: binary, assoc: right};
syntax fixity lapp {arity: binary, assoc: left, same: rapp};
syntax fixity seq {arity: binary, assoc: left, above: [lapp]};
syntax fixity rapp := binary {assoc := right};
syntax fixity lapp := binary {assoc := left; same := rapp};
syntax fixity seq := binary {assoc := left; above := [lapp]};

syntax fixity functor {arity: binary, assoc: right};
syntax fixity functor := binary {assoc := right};

syntax fixity logical {arity: binary, assoc: right, above: [seq]};
syntax fixity comparison {arity: binary, assoc: none, above: [logical]};
syntax fixity logical := binary {assoc := right; above := [seq]};
syntax fixity comparison := binary {assoc := none; above := [logical]};

syntax fixity pair {arity: binary, assoc: right};
syntax fixity cons {arity: binary, assoc: right, above: [pair]};
syntax fixity pair := binary {assoc := right};
syntax fixity cons := binary {assoc := right; above := [pair]};

syntax fixity step {arity: binary, assoc: right};
syntax fixity range {arity: binary, assoc: right, above: [step]};
syntax fixity step := binary {assoc := right};
syntax fixity range := binary {assoc := right; above := [step]};

syntax fixity additive {arity: binary, assoc: left, above: [comparison, range, cons]};
syntax fixity multiplicative {arity: binary, assoc: left, above: [additive]};
syntax fixity additive := binary {assoc := left; above := [comparison; range; cons]};
syntax fixity multiplicative := binary {assoc := left; above := [additive]};

syntax fixity composition {arity: binary, assoc: right, above: [multiplicative]};
syntax fixity composition := binary {assoc := right; above := [multiplicative]};
2 changes: 1 addition & 1 deletion Stdlib/Data/Int/Range.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Range :=
step : Int
};

syntax iterator for {init: 1, range: 1};
syntax iterator for {init := 1; range := 1};

{-# specialize: [1, 3] #-}
for {A} (f : A β†’ Int β†’ A) (a : A) : Range β†’ A
Expand Down
14 changes: 7 additions & 7 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ foldr {A B} (f : A β†’ B β†’ B) (z : B) : List A β†’ B
| nil := z
| (h :: hs) := f h (foldr f z hs);

syntax iterator rfor {init: 1, range: 1};
syntax iterator rfor {init := 1; range := 1};

{-# specialize: [1] #-}
rfor {A B} (f : B β†’ A β†’ B) (acc : B) : List A β†’ B
Expand All @@ -45,20 +45,20 @@ foldl {A B} (f : B β†’ A β†’ B) (z : B) : List A β†’ B
| nil := z
| (h :: hs) := foldl f (f z h) hs;

syntax iterator for {init: 1, range: 1};
syntax iterator for {init := 1; range := 1};

{-# inline: 0 #-}
for : {A B : Type} β†’ (B β†’ A β†’ B) β†’ B β†’ List A β†’ B := foldl;

syntax iterator map {init: 0, range: 1};
syntax iterator map {init := 0; range := 1};

--- π’ͺ(𝓃). Maps a function over each element of a ;List;.
{-# specialize: [1] #-}
map {A B} (f : A β†’ B) : List A β†’ List B
| nil := nil
| (h :: hs) := f h :: map f hs;

syntax iterator filter {init: 0, range: 1};
syntax iterator filter {init := 0; range := 1};

--- π’ͺ(𝓃). Filters a ;List; according to a given predicate, i.e.,
--- keeps the elements for which the given predicate returns ;true;.
Expand Down Expand Up @@ -146,15 +146,15 @@ tail {A} : List A β†’ List A
| (_ :: xs) := xs
| nil := nil;

syntax iterator any {init: 0, range: 1};
syntax iterator any {init := 0; range := 1};

--- π’ͺ(𝓃). Returns ;true; if at least one element of the ;List; satisfies the predicate.
{-# specialize: [1] #-}
any {A} (f : A β†’ Bool) : List A β†’ Bool
| nil := false
| (x :: xs) := if (f x) true (any f xs);

syntax iterator all {init: 0, range: 1};
syntax iterator all {init := 0; range := 1};

--- π’ͺ(𝓃). Returns ;true; if all elements of the ;List; satisfy the predicate.
{-# specialize: [1] #-}
Expand Down Expand Up @@ -220,7 +220,7 @@ catMaybes {A} : List (Maybe A) -> List A
| (just h :: hs) := h :: catMaybes hs
| (nothing :: hs) := catMaybes hs;

syntax iterator concatMap {init: 0, range: 1};
syntax iterator concatMap {init := 0; range := 1};

--- Applies a function to every item on a ;List; and concatenates the result.
--- π’ͺ(𝓃), where 𝓃 is the number of items in the resulting list.
Expand Down
2 changes: 1 addition & 1 deletion Stdlib/Data/Nat/Range.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Range :=
step : Nat
};

syntax iterator for {init: 1, range: 1};
syntax iterator for {init := 1; range := 1};

{-# specialize: [1, 3] #-}
for {A} (f : A β†’ Nat β†’ A) (a : A) : Range β†’ A
Expand Down

0 comments on commit 4facf14

Please sign in to comment.