Skip to content

Commit

Permalink
Use definitions from package-base
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Nov 30, 2023
1 parent 11f8aae commit e37b4ee
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 124 deletions.
7 changes: 1 addition & 6 deletions Stdlib/Data/Bool/Base.juvix
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
module Stdlib.Data.Bool.Base;

import Juvix.Builtin.V1.Bool open public;
import Stdlib.Data.Fixity open;

--- Inductive definition of booleans.
builtin bool
type Bool :=
| true
| false;

--- Logical negation.
not : Bool → Bool
| true := false
Expand Down
22 changes: 1 addition & 21 deletions Stdlib/Data/Fixity.juvix
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
module Stdlib.Data.Fixity;

syntax fixity none := none;

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 := binary {assoc := right};

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

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

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

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

syntax fixity composition := binary {assoc := right; above := [multiplicative]};
import Juvix.Builtin.V1.Fixity open public;
11 changes: 1 addition & 10 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
module Stdlib.Data.List.Base;

import Juvix.Builtin.V1.List open public;
import Stdlib.Data.Fixity open;

import Stdlib.Data.Bool.Base open;
import Stdlib.Function open;
import Stdlib.Data.Nat.Base open;
import Stdlib.Data.Maybe.Base open;
import Stdlib.Trait.Ord open;
import Stdlib.Data.Product.Base open;

syntax operator :: cons;
--- Inductive list.
builtin list
type List (a : Type) :=
| --- The empty list
nil
| --- An element followed by a list
:: a (List a);

--- 𝒪(𝓃). Returns ;true; if the given
--- object is in the ;List;.
{-# specialize: [1] #-}
Expand Down
6 changes: 1 addition & 5 deletions Stdlib/Data/Maybe/Base.juvix
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module Stdlib.Data.Maybe.Base;

--- Represents an optional value that may or may not be present. Provides a way
--- to handle null or missing values in a type-safe manner.
type Maybe A :=
| nothing
| just A;
import Juvix.Builtin.V1.Maybe open public;

--- Extracts the value from a ;Maybe; if present, else returns the given value.
{-# inline: true #-}
Expand Down
12 changes: 1 addition & 11 deletions Stdlib/Data/Nat.juvix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Stdlib.Data.Nat;

import Juvix.Builtin.V1.Nat open public;
import Stdlib.Data.Nat.Base open hiding {+; *; div; mod} public;
-- should be re-exported qualified
import Stdlib.Data.Nat.Base as Nat;
Expand Down Expand Up @@ -31,14 +32,3 @@ ordNatI : Ord Nat := mkOrd Nat.compare;

instance
showNatI : Show Nat := mkShow natToString;

{-# specialize: true, inline: case #-}
instance
naturalNatI : Natural Nat :=
mkNatural@{
+ := (Nat.+);
* := (Nat.*);
div := Nat.div;
mod := Nat.mod;
fromNat (x : Nat) : Nat := x
};
46 changes: 1 addition & 45 deletions Stdlib/Data/Nat/Base.juvix
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
module Stdlib.Data.Nat.Base;

import Stdlib.Data.Fixity open;

--- Inductive natural numbers. I.e. whole non-negative numbers.
builtin nat
type Nat :=
| zero
| suc Nat;

syntax operator + additive;

--- Addition for ;Nat;s.
builtin nat-plus
+ : Nat → Nat → Nat
| zero b := b
| (suc a) b := suc (a + b);

syntax operator * multiplicative;

--- Multiplication for ;Nat;s.
builtin nat-mul
* : Nat → Nat → Nat
| zero _ := zero
| (suc a) b := b + a * b;

--- Truncated subtraction for ;Nat;s.
builtin nat-sub
sub : Nat → Nat → Nat
| zero _ := zero
| n zero := n
| (suc n) (suc m) := sub n m;

--- Division for ;Nat;s. Returns ;zero; if the first element is ;zero;.
builtin nat-udiv
terminating
udiv : Nat → Nat → Nat
| zero _ := zero
| n m := suc (udiv (sub n m) m);

--- Division for ;Nat;s.
builtin nat-div
div (n m : Nat) : Nat := udiv (sub (suc n) m) m;

--- Modulo for ;Nat;s.
builtin nat-mod
mod (n m : Nat) : Nat := sub n (div n m * m);
import Juvix.Builtin.V1.Nat.Base open public;
10 changes: 1 addition & 9 deletions Stdlib/Data/String/Base.juvix
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
module Stdlib.Data.String.Base;

import Juvix.Builtin.V1.String open public;
import Stdlib.Data.List.Base open;
import Stdlib.Function open;
import Stdlib.Data.Fixity open;

--- Primitive representation of a sequence of characters.
builtin string
axiom String : Type;

syntax operator ++str cons;
--- Concatenation of two ;String;s.
builtin string-concat
axiom ++str : String -> String -> String;

--- Concatenates a ;List; of ;String;s.
concatStr : List String -> String := foldl (++str) "";

Expand Down
18 changes: 1 addition & 17 deletions Stdlib/Trait/Natural.juvix
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
module Stdlib.Trait.Natural;

import Stdlib.Data.Nat.Base open using {Nat};
import Stdlib.Data.Fixity open;

trait
type Natural A :=
mkNatural {
syntax operator + additive;
+ : A -> A -> A;
syntax operator * multiplicative;
* : A -> A -> A;
div : A -> A -> A;
mod : A -> A -> A;
builtin from-nat
fromNat : Nat -> A
};

open Natural public;
import Juvix.Builtin.V1.Trait.Natural open public;

0 comments on commit e37b4ee

Please sign in to comment.