Skip to content

Commit

Permalink
Define some array functions
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed Jan 2, 2024
1 parent cc3f966 commit a7cc043
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/rose/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"exports": {
".": "./dist/index.js",
"./ad": "./dist/ad.js",
"./array": "./dist/array.js",
"./num": "./dist/num.js",
"./prelude": "./dist/prelude.js"
},
Expand Down
18 changes: 18 additions & 0 deletions packages/rose/src/array.rose
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use { + } from "./num"

val T => init : u32 => []T

pub val T => len : []T => u32

def T => suffix (f : u32 -> T) (n : u32) (xs : []T) (i : u32) : () =
if i < n then
let _ = xs i = f i
in return suffix f n xs (i + 1)
else ()

pub def T => new (n : u32) (f : u32 -> T) : []T =
let xs = init n
let _ = suffix f n xs 0
in xs

pub def A B => map (f : A -> B) (xs : []A) : []B = new (len xs) (\i => f (xs i))
1 change: 1 addition & 0 deletions packages/rose/src/prelude.rose
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub use { len, map, new } from "./array"
pub use { +, -, *, / } from "./num"
4 changes: 2 additions & 2 deletions packages/vscode/syntaxes/rose.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"patterns": [
{
"name": "keyword.control.rose",
"match": "\\b(else|from|if|pub|then|use)\\b"
"match": "\\b(else|from|if|pub|return|then|use)\\b"
},
{
"name": "keyword.other.rose",
"match": "\\b(and|do|in|or)\\b"
"match": "\\b(and|in|or)\\b"
},
{
"name": "storage.type.rose",
Expand Down

0 comments on commit a7cc043

Please sign in to comment.