Type Declarations

Struct

The struct declaration includes a name, optional generic arguments and a list of fields. The fields in turn have a name and a type which may use the generic arguments.

Examples

// Might be useful as marker, the "unit" type '()' in Rust
struct EmptyStruct {}

// This is just a pair of two fields
struct NonGenericStruct {
    field_a: Type used to represent signed integers. The generic parameter (<N>) specReturns the value of the first branch if the condition is true, otherwise the second branch.
Note that unlike software languages, Spade does not have conditional execution. You do not conditionally assign values inside if expressiosn, you compute a value and return it.
ies the number of bits
, field_b: Type used to represent 1 bit values } // This is a triple with two generic types struct GenericStruct<T, U> { field_a: T, field_b: U, field_c: Type used to represent 1 bit values }

Enum

The enum declaration also includes a name and optional generic arguments. Their body consists of a list of variants. Each variant in turn has a name, and an optional list of fields.

Examples

// Probably not that useful
enum EmptyEnum {}

// This is an enum where some of its variants take parameters
enum NonGenericEnum {
    EmptyVariant,
    OneFieldVariant{val: Type used to represent signed integers. The generic parameter (<N>) specReturns the value of the first branch if the condition is true, otherwise the second branch.
Note that unlike software languages, Spade does not have conditional execution. You do not conditionally assign values inside if expressiosn, you compute a value and return it.
ies the number of bits
}, TwoFieldsVariant{val1: Type used to represent 1 bit values, val2: Type used to represent 1 bit values} } // This is an enum where some of its variants take up to two generic parameters enum GenericEnum<T, U> { EmptyVariant, OneFieldVariant{val: T}, TwoFieldsVariant{val1: T, val2: U} }