From 0886a16d73145270e953b8c2e0a4452b518ea16e Mon Sep 17 00:00:00 2001 From: tslil Date: Fri, 1 May 2026 12:36:24 +0100 Subject: working on fixing app, rework ast to have generics etc --- src/ast.rs | 83 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 44 deletions(-) (limited to 'src/ast.rs') diff --git a/src/ast.rs b/src/ast.rs index fab1236..76b6c9f 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,28 +1,35 @@ use derive_more::Display; -// Set layer +// Generic + +pub trait TypingSignifier { + const SIGNIFIER: &'static str; +} #[derive(Clone, PartialEq, Display, Debug)] -pub enum BuiltIn { - Nat, - Int, - Float, - Str, - Bool, +#[display(".{tag} {bound} => {body}")] +pub struct CaseArm { + pub tag: String, + pub bound: String, + pub body: T, } #[derive(Clone, PartialEq, Display, Debug)] -#[display("{name} : {set}")] -pub struct RecordField { +#[display("{name} {} {carries}", T::SIGNIFIER)] +pub struct Field { pub name: String, - pub set: Set, + pub carries: T, } +// Set layer + #[derive(Clone, PartialEq, Display, Debug)] -#[display("{name} : {set}")] -pub struct VariantField { - pub name: String, - pub set: Set, +pub enum BuiltIn { + Nat, + Int, + Float, + Str, + Bool, } #[derive(Clone, PartialEq, Display, Debug)] @@ -31,10 +38,10 @@ pub enum Set { BuiltIn(BuiltIn), #[display("record {{ {} }}", _0.iter().map(|f| f.to_string()).collect::>().join(" , "))] - Record(Vec), + Record(Vec>), #[display("variant [ {} ]", _0.iter().map(|f| f.to_string()).collect::>().join(" | "))] - Variant(Vec), + Variant(Vec>), #[display("set-of({_0})")] ClaimedSet(Instance), @@ -43,6 +50,10 @@ pub enum Set { Var(String), } +impl TypingSignifier for Set { + const SIGNIFIER: &'static str = ":"; +} + // Signature layer #[derive(Clone, PartialEq, Display, Debug)] @@ -52,20 +63,13 @@ pub struct Param { pub set: Set, } -#[derive(Clone, PartialEq, Display, Debug)] -#[display("{name} :: {signature}")] -pub struct SigField { - pub name: String, - pub signature: Signature, -} - #[derive(Clone, PartialEq, Display, Debug)] pub enum Signature { #[display("Set")] Set, #[display("theory {{ {} }}", _0.iter().map(|f| f.to_string()).collect::>().join(" , "))] - Theory(Vec), + Theory(Vec>), #[display("{} -> {}", params.iter().map(|p| p.to_string()).collect::>().join(", "), codomain)] Ext { @@ -77,6 +81,10 @@ pub enum Signature { Var(String), } +impl TypingSignifier for Signature { + const SIGNIFIER: &'static str = "::"; +} + // Element layer #[derive(Clone, PartialEq, Display, Debug)] @@ -95,14 +103,6 @@ pub struct ElemAssign { pub element: Element, } -#[derive(Clone, PartialEq, Display, Debug)] -#[display(".{tag} {bound} => {body}")] -pub struct CaseArm { - pub tag: String, - pub bound: String, - pub body: Element, -} - #[derive(Clone, PartialEq, Display, Debug)] pub enum Element { #[display("{_0}")] @@ -129,7 +129,7 @@ pub enum Element { #[display("case {} of {{ {} }}", scrutinee, arms.iter().map(|a| a.to_string()).collect::>().join(" | "))] Case { scrutinee: Box, - arms: Vec, + arms: Vec>, }, } @@ -142,14 +142,6 @@ pub struct InstAssign { pub instance: Instance, } -#[derive(Clone, PartialEq, Display, Debug)] -#[display(".{tag} {bound} => {body}")] -pub struct InstCaseArm { - pub tag: String, - pub bound: String, - pub body: Instance, -} - #[derive(Clone, PartialEq, Display, Debug)] pub enum Instance { #[display("({_0} :: Set)")] @@ -167,8 +159,11 @@ pub enum Instance { body: Box, }, - #[display("{_0} {_1}")] - App(Box, Box), + #[display("{instance} {}", args.iter().map(|e| e.to_string()).collect::>().join(" "))] + App { + instance: Box, + args: Vec, + }, #[display("{instance} .{field}")] Project { @@ -179,7 +174,7 @@ pub enum Instance { #[display("case {} of [ {} ]", scrutinee, arms.iter().map(|a| a.to_string()).collect::>().join(" | "))] Case { scrutinee: Box, - arms: Vec, + arms: Vec>, }, } -- cgit v1.3.1