diff --git a/packages/rose/src/ad.rose b/packages/rose/src/ad.rose index 5496ea4..0e892f3 100644 --- a/packages/rose/src/ad.rose +++ b/packages/rose/src/ad.rose @@ -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) { diff --git a/packages/rose/src/array.rose b/packages/rose/src/array.rose index 0dda797..02204af 100644 --- a/packages/rose/src/array.rose +++ b/packages/rose/src/array.rose @@ -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) diff --git a/packages/rose/src/parse.ts b/packages/rose/src/parse.ts index deb5eed..9961abb 100644 --- a/packages/rose/src/parse.ts +++ b/packages/rose/src/parse.ts @@ -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 }; @@ -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, @@ -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 } diff --git a/packages/rose/src/prelude.rose b/packages/rose/src/prelude.rose index d5238d8..4a31ad4 100644 --- a/packages/rose/src/prelude.rose +++ b/packages/rose/src/prelude.rose @@ -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