From 4d26d15460243eeb01e8cab21fb46bf9b849781c Mon Sep 17 00:00:00 2001 From: Elias Mulhall Date: Thu, 1 Aug 2024 17:56:24 -0400 Subject: [PATCH] Update to roc nightly, change Nat to U64 --- .gitignore | 2 ++ package/Array2D.roc | 12 ++++++------ package/Index2D.roc | 10 +++++----- package/Shape2D.roc | 6 +++--- 4 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb68533 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.envrc +*/**/main diff --git a/package/Array2D.roc b/package/Array2D.roc index b6ac4e7..c5740df 100644 --- a/package/Array2D.roc +++ b/package/Array2D.roc @@ -59,7 +59,7 @@ expect empty {} |> toList |> List.len == 0 ## Return an [identity matrix](https://en.wikipedia.org/wiki/Identity_matrix) ## with the specified number of `1`s along the diagonal. -identity : Nat -> Array2D (Num *) +identity : U64 -> Array2D (Num *) identity = \ones -> init { rows: ones, cols: ones } \{ row, col } -> if row == col then 1 else 0 @@ -259,7 +259,7 @@ expect repeat 0 { rows: 3, cols: 4 } |> shape == { rows: 3, cols: 4 } expect empty {} |> shape == { rows: 0, cols: 0 } ## Get the total number of elements in an array. -size : Array2D * -> Nat +size : Array2D * -> U64 size = \@Array2D array -> Shape2D.size array.shape expect repeat 0 { rows: 3, cols: 4 } |> size == 12 @@ -765,7 +765,7 @@ expect ## Run the given function on each element of an array and return the number of ## elements for which the function returned Bool.true. -countIf : Array2D a, (a -> Bool) -> Nat +countIf : Array2D a, (a -> Bool) -> U64 countIf = \@Array2D array, fn -> List.countIf array.data fn ## Return the index of the first element in the array satisfying a predicate @@ -934,18 +934,18 @@ expect a = fromLists [[1, 2, 3], [4, 5, 6]] FitShortest mul a (identity 3) == Ok a -listIndexOf : Shape2D, Index2D -> Result Nat [OutOfBounds] +listIndexOf : Shape2D, Index2D -> Result U64 [OutOfBounds] listIndexOf = \arrayShape, index -> if Shape2D.hasIndex arrayShape index then Ok ((index.row * arrayShape.cols) + index.col) else Err OutOfBounds -arrayIndexOf : Nat, Shape2D -> Index2D +arrayIndexOf : U64, Shape2D -> Index2D arrayIndexOf = \index, { cols } -> { row: index // cols, col: index % cols } -resize : List a, a, Nat -> List a +resize : List a, a, U64 -> List a resize = \list, defaultValue, newLen -> oldLen = List.len list if newLen < oldLen then diff --git a/package/Index2D.roc b/package/Index2D.roc index 0338837..697d227 100644 --- a/package/Index2D.roc +++ b/package/Index2D.roc @@ -22,9 +22,9 @@ interface Index2D exposes [ ] ## Two-dimensional index for referencing elements in an `Array2D`. -Index2D : { row : Nat, col : Nat } +Index2D : { row : U64, col : U64 } -## Add two indices, returning a new index with the sum of the two `row` values +## Add indices, returning a new index with the sum of the two `row` values ## and sum of the two `col` values as component parts. If the resulting index ## is not within the array shape then return `Err OutOfBounds`. add : Index2D, Index2D, Shape2D -> Result Index2D [OutOfBounds] @@ -39,9 +39,9 @@ add = \indexA, indexB, shape -> else Err OutOfBounds -## Add two indices, returning a new index with the difference of the two `row` values -## and difference of the two `col` values as component parts. If the resulting -## index is not within the array shape then return `Err OutOfBounds`. +## Subtract indices, returning a new index with the difference of the two `row` +## values and difference of the two `col` values as component parts. If the +## resulting index is not within the array shape then return `Err OutOfBounds`. sub : Index2D, Index2D, Shape2D -> Result Index2D [OutOfBounds] sub = \indexA, indexB, shape -> result = diff --git a/package/Shape2D.roc b/package/Shape2D.roc index 9463dc8..91f25c4 100644 --- a/package/Shape2D.roc +++ b/package/Shape2D.roc @@ -7,9 +7,9 @@ interface Shape2D exposes [ ## Dimensions of an `Array2D` where `rows` is the total number of rows and ## `cols` is that total number of columns. -Shape2D : { rows : Nat, cols : Nat } +Shape2D : { rows : U64, cols : U64 } -Index2D : { row : Nat, col : Nat } +Index2D : { row : U64, col : U64 } ## Predicate to determine if an array shape can contain indices. When the shape ## has zero rows or zero columns then there is no index that can fall within the @@ -23,5 +23,5 @@ hasIndex = \shape, index -> index.row < shape.rows && index.col < shape.cols ## Total number of elements within the array shape. -size : Shape2D -> Nat +size : Shape2D -> U64 size = \{ rows, cols } -> rows * cols