Skip to content

Commit

Permalink
Tweak the language
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed Jan 10, 2024
1 parent 2d3be12 commit fbfb8cf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/rose/src/ad.rose
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ instance AD u64 {
}

instance AD f32 {
type D = (f32, f32)
type D = f32, f32
}

instance AD f64 {
type D = (f64, f64)
type D = f64, f64
}

instance T (AD T) => AD []T {
type D = []((AD T).D)
type D = [](AD T).D
}

instance A B (AD A) (AD B) => AD (A, B) {
type D = ((AD A).D, (AD B).D)
type D = (AD A).D, (AD B).D
}

instance A B (AD A) (AD B) => AD (A | B) {
Expand Down
10 changes: 5 additions & 5 deletions packages/rose/src/array.rose
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def linearize do_for = do_for

pub def T => new (n : u32) (f : u32 -> T) : []T =
let xs = init n
let _ = do_for (n, \i => set xs i (f i))
let _ = do_for (n, i => set xs i (f i))
in xs

def transpose do_for ((n, f) : (u32, u32 -> ())) : ((), () -> ()) =
def transpose do_for ((n, f) : (u32, u32 -> ())) : (), () -> () =
let g : u32 -> ((), () -> ()) = transpose f
let hs : [](() -> ()) = new n (\i => let (_, h) = g i in h)
in ((), \() => do_for (n, \i => hs i ()))
let hs : [](() -> ()) = new n i => let _, h = g i in h
in (), () => do_for (n, i => hs i ())

pub def A B => map (f : A -> B) (xs : []A) : []B = new (len xs) (\i => f (xs i))
pub def A B => map (f : A -> B) (xs : []A) : []B = new (len xs) i => f (xs i)
20 changes: 14 additions & 6 deletions packages/rose/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,21 @@ export interface Class {
}

export enum TypeKind {
Unit,
Name,
Class,
Array,
Tuple,
Pair,
Sum,
Function,
}

export type Type =
| { kind: TypeKind.Unit }
| { kind: TypeKind.Name; name: TokenId }
| { kind: TypeKind.Class; class: Class; name: TokenId }
| { kind: TypeKind.Array; elem: Type }
| { kind: TypeKind.Tuple; member: Type[] }
| { kind: TypeKind.Pair; left: Type; right: Type }
| { kind: TypeKind.Sum; left: Type; right: Type }
| { kind: TypeKind.Function; dom: Type; cod: Type };

Expand All @@ -103,19 +105,23 @@ export interface Param {
}

export enum BindKind {
Unit,
Name,
Tuple,
Pair,
}

export type Bind =
| { kind: BindKind.Unit }
| { kind: BindKind.Name; name: TokenId }
| { kind: BindKind.Tuple; member: Bind[] };
| { kind: BindKind.Pair; left: Bind; right: Bind };

export enum ExprKind {
Name,
Unit,
Str,
Num,
Array,
Tuple,
Pair,
Inl,
Inr,
Lambda,
Expand All @@ -130,9 +136,11 @@ export enum ExprKind {

export type Expr =
| { kind: ExprKind.Name; name: TokenId }
| { kind: ExprKind.Unit }
| { kind: ExprKind.Str; str: TokenId }
| { kind: ExprKind.Num; num: TokenId }
| { kind: ExprKind.Array; elem: Expr[] }
| { kind: ExprKind.Tuple; member: Expr[] }
| { kind: ExprKind.Pair; left: Expr; right: Expr }
| { kind: ExprKind.Inl; val: Expr }
| { kind: ExprKind.Inr; val: Expr }
| { kind: ExprKind.Lambda; param: Param; body: Expr }
Expand Down
4 changes: 4 additions & 0 deletions packages/rose/src/prelude.rose
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
pub use { len, map, new } from "./array.js"
pub use { +, -, *, / } from "./num.js"

pub def true = bool.true

pub def false = bool.false

0 comments on commit fbfb8cf

Please sign in to comment.