Skip to content

Commit

Permalink
rename ℕ by Nat in the tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored and lukaszcz committed Sep 29, 2022
1 parent 5024dad commit b4109a1
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 59 deletions.
14 changes: 7 additions & 7 deletions examples/milestone/Collatz/Collatz.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ mapMaybe : {A : Type} → {B : Type} → (A → B) → Maybe A → Maybe B;
mapMaybe _ nothing := nothing;
mapMaybe f (just x) := just (f x);

div2 : → Maybe ;
div2 : Nat → Maybe Nat;
div2 zero := just zero;
div2 (suc (suc n)) := mapMaybe suc (div2 n);
div2 _ := nothing;

collatzNext : ;
collatzNext : NatNat;
collatzNext n := fromMaybe (suc (3 * n)) (div2 n);

collatz : ;
collatz : NatNat;
collatz zero := zero;
collatz (suc zero) := suc zero;
collatz (suc (suc n)) := collatzNext (suc (suc n));
Expand All @@ -28,20 +28,20 @@ compile readline {
c ↦ "readline()";
};

axiom parsePositiveInt : String → ;
axiom parsePositiveInt : String → Nat;

compile parsePositiveInt {
c ↦ "parsePositiveInt";
};

getInitial : ;
getInitial : Nat;
getInitial := parsePositiveInt (readline);

output : × IO;
output : NatNat × IO;
output n := (n, putStrLn (natToStr n));

terminating
run : () → → IO;
run : (NatNat) → Nat → IO;
run _ (suc zero) := putStrLn "Finished!";
run f n := run f (fst (output (f n)));

Expand Down
4 changes: 2 additions & 2 deletions examples/milestone/Fibonacci/Fibonacci.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module Fibonacci;

open import Stdlib.Prelude;

fib : ;
fib : NatNatNatNat;
fib zero x1 _ := x1;
fib (suc n) x1 x2 := fib n x2 (x1 + x2);

fibonacci : ;
fibonacci : NatNat;
fibonacci n := fib n 0 1;

main : IO;
Expand Down
6 changes: 3 additions & 3 deletions examples/milestone/Hanoi/Hanoi.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ unlines := intercalate "\n";
singleton : {A : Type} → A → List A;
singleton a := a ∷ nil;

--- Produce a ;String; representation of a ;List ;
showList : List → String;
--- Produce a ;String; representation of a ;List Nat;
showList : List Nat → String;
showList xs := "[" ++str intercalate "," (map natToStr xs) ++str "]";

--- A Peg represents a peg in the towers of Hanoi game
Expand All @@ -64,7 +64,7 @@ showMove : Move → String;
showMove (move from to) := showPeg from ++str " -> " ++str showPeg to;

--- Produce a list of ;Move;s that solves the towers of Hanoi game
hanoi : → Peg → Peg → Peg → List Move;
hanoi : Nat → Peg → Peg → Peg → List Move;
hanoi zero _ _ _ := nil;
hanoi (suc n) p1 p2 p3 := hanoi n p1 p3 p2 ++ singleton (move p1 p2) ++ hanoi n p3 p2 p1;

Expand Down
8 changes: 4 additions & 4 deletions examples/milestone/PascalsTriangle/PascalsTriangle.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ zipWith f _ nil := nil;
zipWith f (x ∷ xs) (y ∷ ys) := f x y ∷ zipWith f xs ys;

--- Return a list of repeated applications of a given function
iterate : {A : Type} → → (A → A) → A → List A;
iterate : {A : Type} → Nat → (A → A) → A → List A;
iterate zero _ _ := nil;
iterate (suc n) f a := a ∷ iterate n f (f a);

Expand Down Expand Up @@ -43,15 +43,15 @@ intercalate sep xs := concat (intersperse sep xs);
unlines : List String → String;
unlines := intercalate "\n";

showList : List → String;
showList : List Nat → String;
showList xs := "[" ++str intercalate "," (map natToStr xs) ++str "]";

--- Compute the next row of Pascal's triangle
pascalNextRow : List → List ;
pascalNextRow : List Nat → List Nat;
pascalNextRow row := zipWith (+) (singleton zero ++ row) (row ++ singleton zero);

--- Produce Pascal's triangle to a given depth
pascal : → List (List );
pascal : Nat → List (List Nat);
pascal rows := iterate rows pascalNextRow (singleton one);

main : IO;
Expand Down
6 changes: 3 additions & 3 deletions examples/milestone/TicTacToe/CLI/TicTacToe.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ compile readline {
c ↦ "readline()";
};

axiom parsePositiveInt : String → ;
axiom parsePositiveInt : String → Nat;

compile parsePositiveInt {
c ↦ "parsePositiveInt";
};

-- | Reads a ;; from stdin
getMove : Maybe ;
-- | Reads a ;Nat; from stdin
getMove : Maybe Nat;
getMove := validMove (parsePositiveInt (readline));

do : IO × GameState -> GameState;
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/TicTacToe/Logic/Board.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ inductive Board {
};

--- Returns the list of numbers corresponding to the empty ;Square;s
possibleMoves : List Square → List ;
possibleMoves : List Square → List Nat;
possibleMoves nil := nil;
possibleMoves ((empty n) ∷ xs) := n ∷ possibleMoves xs;
possibleMoves (_ ∷ xs) := possibleMoves xs;
Expand Down
6 changes: 3 additions & 3 deletions examples/milestone/TicTacToe/Logic/Game.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checkState (state b p e) :=
(state b p e));

--- Given a player attempted move, updates the state accordingly.
playMove : Maybe → GameState → GameState;
playMove : Maybe Nat → GameState → GameState;
playMove nothing (state b p _) :=
state b p (continue "\nInvalid number, try again\n");
playMove (just k) (state (board s) player e) :=
Expand All @@ -32,8 +32,8 @@ playMove (just k) (state (board s) player e) :=
(switch player)
noError));

--- Returns ;just; if the given ;; is in range of 1..9
validMove : → Maybe ;
--- Returns ;just; if the given ;Nat; is in range of 1..9
validMove : Nat → Maybe Nat;
validMove n := if ((n <= nine) && (n >= one)) (just n) nothing;

end;
6 changes: 3 additions & 3 deletions examples/milestone/TicTacToe/Logic/Square.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ open import Logic.Extra;

--- A square is each of the holes in a board
inductive Square {
--- An empty square has a ;; that uniquely identifies it
empty : → Square;
--- An empty square has a ;Nat; that uniquely identifies it
empty : Nat → Square;
--- An occupied square has a ;Symbol; in it
occupied : Symbol → Square;
};
Expand All @@ -24,7 +24,7 @@ showSquare : Square → String;
showSquare (empty n) := " " ++str natToStr n ++str " ";
showSquare (occupied s) := " " ++str showSymbol s ++str " ";

replace : Symbol → → Square → Square;
replace : Symbol → Nat → Square → Square;
replace player k (empty n) := if (n Stdlib.Data.Nat.Ord.== k) (occupied player) (empty n);
replace _ _ s := s;

Expand Down
40 changes: 20 additions & 20 deletions examples/milestone/TicTacToe/Web/TicTacToe.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ open import Logic.Game;
axiom hostLog : String → IO;

-- XCoord → YCoord → Width → Height → Color → IO
axiom hostFillRect : → String → IO;
axiom hostFillRect : NatNatNatNat → String → IO;

-- XCoord → YCoord → Text → Size → Color → Align → IO
axiom hostFillText : → String → → String → → IO;
axiom hostFillText : NatNat → String → Nat → String → Nat → IO;

-- Nat extension

Expand All @@ -30,7 +30,7 @@ foreign c {
};

infixl 7 div;
axiom div : ;
axiom div : NatNatNat;

compile div {
c ↦ "div";
Expand All @@ -55,31 +55,31 @@ zip : {A : Type} → {B : Type} → List A → List B → List (A × B);
zip (a ∷ as) (b ∷ bs) := (a, b) ∷ zip as bs;
zip _ _ := nil;

rangeAux : → List ;
rangeAux : NatNat → List Nat;
rangeAux _ zero := nil;
rangeAux m (suc n) := m ∷ rangeAux (suc m) n;

range : → List ;
range : Nat → List Nat;
range n := rangeAux zero n;

enumerate : {A : Type} → List A → List ( × A);
enumerate : {A : Type} → List A → List (Nat × A);
enumerate l := zip (range (length l)) l;

-- Formatting constants

squareWidth : ;
squareWidth : Nat;
squareWidth := 100;

textSize : ;
textSize : Nat;
textSize := 30;

xTextOffset : ;
xTextOffset : Nat;
xTextOffset := 50;

yTextOffset : ;
yTextOffset : Nat;
yTextOffset := 60;

canvasPadding : ;
canvasPadding : Nat;
canvasPadding := 8;

textColor : String;
Expand All @@ -99,32 +99,32 @@ inductive Align {
center : Align;
};

alignNum : Align → ;
alignNum : Align → Nat;
alignNum left := zero;
alignNum right := one;
alignNum center := two;

renderText : String → → Align → IO;
renderText : String → NatNat → Align → IO;
renderText t row col a := hostFillText ((squareWidth * row) + xTextOffset) ((squareWidth * col) + yTextOffset) t textSize textColor (alignNum a);

renderSymbol : Symbol → → IO;
renderSymbol : Symbol → NatNat → IO;
renderSymbol s row col := renderText (showSymbol s) row col center;

renderNumber : → IO;
renderNumber : NatNatNat → IO;
renderNumber n row col := renderText (natToStr n) row col center;

renderSquare : → Square → IO;
renderSquare : NatNat → Square → IO;
renderSquare row col (occupied s) :=
hostFillRect (squareWidth * row) (squareWidth * col) squareWidth squareWidth backgroundColor
>> renderSymbol s row col;
renderSquare row col (empty n) :=
hostFillRect (squareWidth * row) (squareWidth * col) squareWidth squareWidth lightBackgroundColor
>> renderNumber n row col;

renderRowAux : → ( × Square) → IO;
renderRowAux : Nat → (Nat × Square) → IO;
renderRowAux col (row, s) := renderSquare row col s;

renderRow : × (List Square) → IO;
renderRow : Nat × (List Square) → IO;
renderRow (n, xs) := mapIO (renderRowAux n) (enumerate xs);

renderBoard : Board → IO;
Expand All @@ -149,15 +149,15 @@ renderGameState (state b p _) := renderBoard b >> renderFooterText (nextPlayerTe
renderAndReturn : GameState → GameState;
renderAndReturn s := const s (renderGameState s);

selectedSquare : ;
selectedSquare : NatNatNat;
selectedSquare row col := 3 * (col div squareWidth) + (row div squareWidth) + 1;

-- API

initGame : GameState;
initGame := const beginState (renderGameState beginState >> renderText "Click on a square to make a move" 0 4 left);

move : GameState → → GameState;
move : GameState → NatNat → GameState;
move (state b p (terminate e)) x y := renderAndReturn (state b p (terminate e));
move s x y := renderAndReturn (playMove (validMove (selectedSquare x y)) s);

Expand Down
2 changes: 1 addition & 1 deletion tests/positive/Internal/LiteralInt.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ module LiteralInt;
b : B;
};

f : ;
f : Nat;
f := 1;
end;
2 changes: 1 addition & 1 deletion tests/positive/MiniC/ExportName/Input.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Input;

open import Stdlib.Prelude;

fun : ;
fun : Nat;
fun := six;

end;
2 changes: 1 addition & 1 deletion tests/positive/MiniC/ExportNameArgs/Input.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Input;

open import Stdlib.Prelude;

fun : ;
fun : NatNat;
fun _ := three;

end;
2 changes: 1 addition & 1 deletion tests/positive/StdlibImport/StdlibImport.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open import Stdlib.Prelude;

import A;

two : ;
two : Nat;
two := 1 + 1;

foo : A.Foo;
Expand Down
18 changes: 9 additions & 9 deletions tests/positive/Symbols.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ module Symbols;

open import Stdlib.Data.Nat;

╘⑽╛ : ;
╘⑽╛ : Nat;
╘⑽╛ := suc nine;

-- no - function!?
- : -> -> ;
- : Nat -> Nat -> Nat;
- := (+);

(-) : -> -> ;
(-) : Nat -> Nat -> Nat;
(-) := (-);

(*) : -> -> ;
(*) : Nat -> Nat -> Nat;
(*) := (*);

infixl 6 -;
- : -> -> ;
- : Nat -> Nat -> Nat;
- := (-);

infixl 7 ·;
· : -> -> ;
· : Nat -> Nat -> Nat;
· := (*);

(0) : ;
(0) : Nat;
(0) := ╘⑽╛ - ╘⑽╛ · zero;

主功能 : ;
主功能 : Nat;
主功能 := (0);
end;
end;

0 comments on commit b4109a1

Please sign in to comment.