pub enum Expr {
Var(Arc<str>),
Lam(Arc<str>, Box<Self>),
App(Box<Self>, Box<Self>),
Lit(Literal),
Record(Vec<(Arc<str>, Self)>),
List(Vec<Self>),
Field(Box<Self>, Arc<str>),
Index(Box<Self>, Box<Self>),
Match {
scrutinee: Box<Self>,
arms: Vec<(Pattern, Self)>,
},
Let {
name: Arc<str>,
value: Box<Self>,
body: Box<Self>,
},
Builtin(BuiltinOp, Vec<Self>),
}Expand description
An expression in the pure functional language.
All variants are serializable, content-addressable, and evaluate deterministically on any platform (including WASM).
Variants§
Var(Arc<str>)
Variable reference.
Lam(Arc<str>, Box<Self>)
Lambda abstraction: λparam. body.
App(Box<Self>, Box<Self>)
Function application: func(arg).
Lit(Literal)
Literal value.
Record(Vec<(Arc<str>, Self)>)
Record construction: { name: expr, ... }.
List(Vec<Self>)
List construction: [expr, ...].
Field(Box<Self>, Arc<str>)
Field access: expr.field.
Index(Box<Self>, Box<Self>)
Index access: expr[index].
Match
Pattern matching: match scrutinee { pat => body, ... }.
Fields
Let
Let binding: let name = value in body.
Fields
Builtin(BuiltinOp, Vec<Self>)
Built-in operation applied to arguments.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn let_in(name: impl Into<Arc<str>>, value: Self, body: Self) -> Self
pub fn let_in(name: impl Into<Arc<str>>, value: Self, body: Self) -> Self
Create a let-binding expression.
Sourcepub const fn builtin(op: BuiltinOp, args: Vec<Self>) -> Self
pub const fn builtin(op: BuiltinOp, args: Vec<Self>) -> Self
Create a builtin operation applied to arguments.
Sourcepub fn int_to_float(arg: Self) -> Self
pub fn int_to_float(arg: Self) -> Self
Coerce an integer to a float.
Sourcepub fn float_to_int(arg: Self) -> Self
pub fn float_to_int(arg: Self) -> Self
Coerce a float to an integer (truncates toward zero).
Sourcepub fn int_to_str(arg: Self) -> Self
pub fn int_to_str(arg: Self) -> Self
Coerce an integer to a string.
Sourcepub fn float_to_str(arg: Self) -> Self
pub fn float_to_str(arg: Self) -> Self
Coerce a float to a string.
Sourcepub fn str_to_int(arg: Self) -> Self
pub fn str_to_int(arg: Self) -> Self
Parse a string as an integer.
Sourcepub fn str_to_float(arg: Self) -> Self
pub fn str_to_float(arg: Self) -> Self
Parse a string as a float.