Prelude-defined forms
tensor, layer, and model are declared with form descriptors rather than compiler primitives. Swapping or tightening a constraint is a prelude edit.
Forma for Effect Torch · pre-alpha exploration
Most machine learning code hides tensor shapes, dtypes, and layer wiring inside imperative scripts until a forward pass crashes at runtime. @forma/effect-torch is an exploratory Forma prelude that expresses tensors, layers, and models as checked declarations targeting @effect-torch/core. The prelude, typechecker, and canonical IR run in the browser sandbox today; TypeScript emission and live Preview Portal execution are planned.
(tensor input :shape [64 784] :dtype :f32) (layer fc1 :in 784 :out 256 :act :relu) (model mlp :input input :layers [fc1 fc2]) │ │ read → project → check → IR ▼ Canonical Graph IR (checked today) └─→ @effect-torch/core TS (planned)
Pre-alpha exploration · editable prelude in the sandbox
00 The problem
In Python and TypeScript ML code, tensor dimensions and dtypes are mostly comments or runtime assertions. A mismatched layer width or precision bug compiles cleanly and surfaces only after data loads. Forma treats the model graph as typed vocabulary, so the compiler can validate declarations and project a structured IR before any runtime allocates a buffer.
Graph vocabulary
Declarations as data, checked as types.
None of these forms are hardcoded into the Forma compiler. The sandbox mounts @forma/effect-torch as an ordinary prelude package defining tensor, layer, and model with typed slots and canonical IR projections.
Every declaration is checked by Forma's Hindley–Milner typechecker: dtypes come from a closed keyword union, shapes and layer widths are typed integer slots, and model graphs resolve layer references against declared bindings. Because the prelude itself is editable in the sandbox, you can inspect or extend the descriptors directly.
(tensor x-in
:shape [64 784]
:dtype :f32)
(layer fc1
:in 784
:out 256
:activation :relu)
(layer fc2
:in 256
:out 10
:activation :softmax)
(model mnist-mlp
:input x-in
:layers [fc1 fc2])Implemented vs. planned
Honest scope for a pre-alpha prelude.
Today, @forma/effect-torch demonstrates how a tensor-graph DSL fits into Forma's prelude system without compiler changes. Opening the sandbox gives you live typechecking, hover types, located diagnostics, and copy-on-write editing of both src/mlp.lisp and the mounted prelude package.
What is planned rather than shipped: a dedicated TypeScript emitter targeting @effect-torch/core, symbolic dimension arithmetic across arbitrary layer chains and broadcasting rules, and a live Preview Portal view that renders graph topology and tensor statistics in the browser.
03 Architecture
The goal is a declarative graph layer that compiles cleanly onto Effect's structured resource and error model in @effect-torch/core.
tensor, layer, and model are declared with form descriptors rather than compiler primitives. Swapping or tightening a constraint is a prelude edit.
Passing declarations project to structured IR records with explicit shapes, dtypes, and references—ready for static analysis or downstream code generation.
Inspect the mounted @forma/effect-torch package in the browser, modify a form descriptor, and watch diagnostics update live against src/mlp.lisp.
Planned TypeScript generation will emit typed @effect-torch/core modules where device allocation, training steps, and tensor errors stay inside Effect.
04 Limits
This is an early exploration of ML vocabulary on a pre-alpha language. Do not expect a training framework.
@effect-torch/core and host TypeScript.@effect-torch/core code.05 Fit
@effect-torch/core.@effect-torch/core code or symbolic shape proofs now.Open the Effect Torch sandbox to read the mounted @forma/effect-torch descriptors alongside src/mlp.lisp and test live diagnostics in your browser.