Skip to content

First program

Start with a small Surf function, format it, check it, then ask the compiler to show the canonical Deep form.

Create app.ch:

def relu_then_softmax(x: tensor[n, f32]) -> tensor[n, f32] =
x |> relu |> softmax(0)

Then run:

Terminal window
chelis fmt --inplace app.ch
chelis check app.ch
chelis deep app.ch > app.dp
chelis surf app.dp

check, deep, and surf are useful together: Surf stays readable for humans, while Deep is the stable machine form that shell tooling can inspect.

(defsig {}
relu_then_softmax
(t-fn {}
(t-tensor {} (d-name {} n) (t-prim {} f32))
(t-tensor {} (d-name {} n) (t-prim {} f32))))
(def {}
relu_then_softmax
(fn {}
(params {} (x {type: (t-tensor {} (d-name {} n) (t-prim {} f32))}))
(pipe {}
(var {} x)
(var {} relu)
(app {} (var {} softmax) (lit {type: (t-prim {} int32)} 0)))))

Check a program:

Terminal window
chelis check app.ch

Print canonical Deep:

Terminal window
chelis deep app.ch

Convert Deep back to Surf:

Terminal window
chelis surf app.dp

Build source artifacts without invoking a native compiler:

Terminal window
chelis build app.ch --target c --output out/