MIND is a statically-typed, tensor-native language designed for AI and numerical computing. This page covers the core syntax and type system.
Basic Syntax
MIND uses a Rust-inspired syntax with first-class tensor support:
// Function definition (opaque tensor<dtype> accepts any shape)
fn relu(x: tensor<f32>) -> tensor<f32> {
max(x, 0.0)
}
// Main entry point
fn main() {
let x: Tensor<f32, 2, 3> = [[1.0, -2.0, 3.0], [-1.0, 2.0, -3.0]];
let y = relu(x);
print(y);
}Type System
MIND features a rich type system with compile-time shape checking:
f32f64i32i64bool
Scalar types
f32, f64, i32, i64, bool
f16bf16
Half-precision
f16, bf16 for mixed-precision training
f32 == F32Case-insensitive dtypes
f32 and F32 are equivalent, same for bf16/BF16, i32/I32
Tensor<dtype, ...dims>Tensor types
Tensor<dtype, ...dims> with static or dynamic shapes
Tensor<f32, 2, 3>Static shapes
Dimensions are concrete integers at compile time; generic/polymorphic shape syntax is not yet in the surface parser
@cpu@gpu (reserved)
Device annotations
@cpu for CPU placement control (@gpu syntax reserved; GPU execution provided by the commercial mind-runtime)
Type Annotation Syntax
Two equivalent forms for tensor type annotations:
// Lowercase with commas (Rust-style)
let x: Tensor<f32, 2, 3> = zeros();
// Uppercase with bracket dims (ML-style), concrete dims
let y: Tensor<F32, 4, 8> = zeros();
// Opaque tensor (no shape annotation)
fn relu(x: tensor<f32>) -> tensor<f32> { max(x, 0.0) }Tensor Literals
// 1D tensor
let v: Tensor<f32, 3> = [1.0, 2.0, 3.0];
// 2D tensor (matrix)
let m: Tensor<f32, 2, 3> = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
// Random initialization
let w: Tensor<f32, 784, 128> = randn();
// Zeros/ones
let zeros: Tensor<f32, 10, 10> = zeros();
let ones: Tensor<i32, 5> = ones();Functions
// Regular function with concrete shapes
fn add(a: Tensor<f32, 128>, b: Tensor<f32, 128>) -> Tensor<f32, 128> {
a + b
}
// Differentiable function (opaque tensor form accepts any shape)
@differentiable
fn loss(pred: tensor<f32>, target: tensor<f32>) -> f32 {
mean((pred - target) ** 2)
}
// Note: generics are a bounded slice today — a single type parameter over
// scalar types, monomorphized at compile time. Generic shape parameters (N, M)
// have no surface syntax yet; use concrete dims or the opaque tensor<dtype> formOperators
MIND supports arithmetic, comparison, and logical operators on both scalars and tensors:
| Category | Operators | Notes |
|---|---|---|
| Arithmetic | + - * / | Element-wise on tensors, broadcasting supported |
| Comparison | < <= > >= == != | Returns boolean tensor or scalar |
| Unary | -x | Negation for scalars and tensors |
| Assignment | = | Immutable by default, let mut for mutable |
// Comparison operators work on scalars and tensors
let mask = scores > 0.5; // element-wise comparison
let valid = count >= threshold; // scalar comparison
let equal = pred == target; // equality checkControl Flow
// Conditionals
fn activation(x: f32, use_relu: bool) -> f32 {
if use_relu {
max(x, 0.0)
} else {
tanh(x)
}
}
// Loops (bounded for determinism)
fn sum_first_n(x: Tensor<f32, 100>, n: i32) -> f32 {
let mut acc = 0.0;
for i in 0..n {
acc = acc + x[i];
}
acc
}
// Print for debugging
print(acc);Executable Subset Status
The compiler executes a growing subset of the specified language. An honest snapshot of what ships today:
- Shipped
Enums, generics, fixed-point arithmetic
Enums with pattern matching (sum types in the
Result/Optionstyle), bounded generics (a single type parameter over scalar types, monomorphized), deterministic integer and Q16.16 fixed-point arithmetic - Partial
Collections and slices
Collections are a region allocator plus an insert-only map, not full
Vec/String/HashMap; slices (&[T]) are stubbed - Not yet
Closures, traits, generic shapes
Closures and first-class function values (calling a function value is rejected with a clear diagnostic), traits, generic shape parameters
Learn More
See the full language specification at mind-spec/language.md.