Initial set of primitives
Implement the primitives described in the list below. See Notes to coordinate with other tasks.
Note on JIT (#27)
- If common functions are kept as
defs (e.g. map / fold / length / concat / split),
a JIT could accelerate them without turning them into primitives.
Note on FFI (#28)
read_file / write_file might be implemented via FFI with C,
instead of dedicated primitives.
Proposed primitives
Debug / observability (can inspect without consuming the term)
- Rationale: inspect terms in lazy mode without altering evaluation.
%show(x: a) -> String
- Stringifies without reducing and without consuming the term.
- Use the current printing format (normalize mode / no collapse).
%trace(msgs: List<String>, x: a) -> a
- Prints the concatenation of
msgs and returns x without consuming it.
- Use the current printing format (normalize mode / no collapse).
Control / error
- Rationale: explicit failures and error messages.
%panic(msg: String) -> a
- Aborts with a message; only triggers if evaluated.
IO
- Rationale: basic input/output effects with explicit errors.
%log(s: String) -> #Nil (existing)
String = list of #Chr.
- Kept as-is (returns
[]).
%read_file(path: String) -> #Ok{String} | #Err{String}
- IO with explicit error; no silent failure.
%write_file(path: String, data: String) -> #Ok{} | #Err{String}
%read_bytes(path: String) -> #Ok{List<#U8{NUM}>} | #Err{String}
- Byte =
#U8{n} with n stored in 8 bits.
%write_bytes(path: String, data: List<#U8{NUM}>) -> #Ok{} | #Err{String}
- Byte =
#U8{n} with n stored in 8 bits.
Effects / nondeterminism
- Rationale: time and RNG utilities while keeping clear semantics.
%time_ms() -> NUM
- Monotonic; effectful; result depends on when it is demanded.
%rand(seed: NUM, bits: NUM) -> #Pair{seed2, value}
- Pure/deterministic PRNG;
bits defines width.
- Supported term bit sizes:
- 7 (TAG), 24 (EXT), 32 (VAL).
- Supported common sizes: 8 / 16 / 64.
bits outside this set: panic.
Common FP utilities
- Rationale: basic library building blocks; decide whether they remain defs or become primitives.
- Lists:
map, fold, length, concat, split
- Strings:
num_to_str, str_to_num
Initial set of primitives
Implement the primitives described in the list below. See Notes to coordinate with other tasks.
Note on JIT (#27)
defs(e.g.map/fold/length/concat/split),a JIT could accelerate them without turning them into primitives.
Note on FFI (#28)
read_file/write_filemight be implemented via FFI with C,instead of dedicated primitives.
Proposed primitives
Debug / observability (can inspect without consuming the term)
%show(x: a) -> String%trace(msgs: List<String>, x: a) -> amsgsand returnsxwithout consuming it.Control / error
%panic(msg: String) -> aIO
%log(s: String) -> #Nil(existing)String= list of#Chr.[]).%read_file(path: String) -> #Ok{String} | #Err{String}%write_file(path: String, data: String) -> #Ok{} | #Err{String}%read_bytes(path: String) -> #Ok{List<#U8{NUM}>} | #Err{String}#U8{n}withnstored in 8 bits.%write_bytes(path: String, data: List<#U8{NUM}>) -> #Ok{} | #Err{String}#U8{n}withnstored in 8 bits.Effects / nondeterminism
%time_ms() -> NUM%rand(seed: NUM, bits: NUM) -> #Pair{seed2, value}bitsdefines width.bitsoutside this set:panic.Common FP utilities
map,fold,length,concat,splitnum_to_str,str_to_num