Reference /docs/language-spec

Language Specification

Cure Language Specification

Syntax Overview

Cure is an indentation-structured language. Blocks are delimited by indentation level, not by keywords like do / end or braces.

Keywords

The active edition reserves the words reported by the lexer. The declaration and expression keywords most users encounter are:

fn , mod , rec , fsm , actor , interface , implementation , type , typealias , primitive , let , pickup , else , match , with , when , local , use , return , throw , try , catch , finally , for , in , true , false , nil , and , or , not , spawn , send , receive , after , unsafe , quote , syntax , becomes , computed , by , end , and do .

requires is contextual in function and implementation signatures. It lists interface obligations without reserving the word as an ordinary identifier:

fn show_both(a: t, b: t) -> String requires Show(t) =
  show(a) <> show(b)

where is reserved for declaration-local definition blocks. The former constraint spelling fn ... where Interface(t) is deprecated; the parser still accepts it during migration and the printer canonicalizes it to requires .

sup is a contextual soft keyword: at the lexer level it is an ordinary identifier so legacy code that uses it as a field or variable name keeps compiling; the parser dispatches sup to the supervisor container only at statement-prefix position.

app is a contextual soft keyword with the same treatment: app at statement-prefix position opens an application container; every other use of app remains a plain identifier.

Identifiers

Identifiers may carry a trailing ? to signal a predicate (Elixir convention):

fn even?(n: Int) -> Bool = n % 2 == 0
fn is_empty?(xs: List(t)) -> Bool = ...

The ! suffix is reserved for effect annotations and FSM hard events.

Comments and docstrings

  • # ... — line comment.
  • ## text — single-line doc comment. One per line; attached to the following definition. Consecutive ## blocks separated by a blank-line gap (or by plain # comments that the lexer drops) are merged into a single docstring with a paragraph break between blocks. This lets you write a long docstring in natural paragraphs without leaving orphan :doc_comment tokens ahead of the next definition.
  • ###\n...\n### — fenced multi-line doc comment. Opens on a line whose first three non-whitespace characters are ### ; closes on the next line whose first three non-whitespace characters are ### . Leading indentation common to every body line is stripped.
  • Docstring body grammar. Doc-comment bodies are Markdown: cure doc tooling ( Cure.Doc.Markdown , cure doc , the REPL's :doc / :help output, and the Cure website's /stdlib/:module pages) pipe the body through the NIF-free :md library. Fenced code blocks carrying a known language ( cure , elixir , erlang ) are syntax-highlighted via Makeup; unknown languages pass through with a stable language- class for downstream CSS. The strings and are substituted for the running Cure version before parsing so release-sensitive copy can travel inside docstrings.

Declarations

Cure's declarations are indentation-scoped and have no closing delimiter:

Declaration Purpose
mod Name Opens a module; the body is everything indented under it.
fn name(args) -> T A function. Public functions require a return type.
local fn A function private to its module.
type Name = ... An algebraic data type (sum type).
rec Name A record (named product type).
typealias A transparent type alias.
interface Name(t) An interface declaration.
implementation Name for T An interface implementation.
fsm Name with Data A state machine (see FSM Guide ).
actor Name A typed gen_server (see Supervision ).
sup Name A typed supervision tree.
app Name An OTP application (see Applications ).

Modules and imports

use Std.X imports a standard-library module; use SomeModule imports a project module. Imports are not ambient — a missing use surfaces as an unknown constructor or value ( E091 ), not as a mysterious arity error.

Module identity comes from the mod declaration, not the filename, so lib/calculator_core.cure may declare mod Calc and use Calc will still find it.

Branching

match and pickup are the only branching constructs.

  • match dispatches on structural shape; see Match and Patterns .
  • pickup dispatches on free-standing boolean guards, with else as the fallback:
pickup
  y == 0.0 -> Error("division by zero")
  else     -> Ok(x / y)

Further reading