Types
KataScript values have runtime types. Types are themselves values: they can be printed, compared, and stored in bindings. typeof(value) returns a type value.
Primitive values
Section titled “Primitive values”| Type | Values and construction |
|---|---|
Int | Arbitrary-precision integers: 42, 0xff, 0b1010 |
Float | Approximate 64-bit floating point: 3.5 |
Bool | true and false |
Nil | The absent scalar value nil |
Str | Unicode text: "hello" or 'hello' |
Bin | Byte sequences: b'hello\xff' |
Byte | One byte, obtained for example by indexing a Bin |
Char | One Unicode scalar value, obtained from Str.chars() |
Func | Function values; no parameterized function-signature type |
RawPtr | Opaque pointer used by low-level memory facilities |
Single quotes create Str, not Char. nil is distinct from an absent Opt[T]; optional values explicitly carry their intended element type.
print(typeof(42))print(typeof("hello"))print(typeof(b'A'[0]))print(typeof("A".chars()[0]))print(Int)Fixed-width numbers
Section titled “Fixed-width numbers”The runtime also has unsigned U8, U16, U32, U64, U128; signed I8, I16, I32, I64, I128; platform-sized Usz and Isz; and floating-point F16, F32, F64 types. These are distinct types rather than suffixes on literal tokens. Ordinary integer literals produce Int, and ordinary decimal literals produce Float.
Construct an explicit numeric type by calling it with a value. Integer constructors check the representable range, and fixed-width integer arithmetic reports overflow rather than silently wrapping.
let small = U8(42)let fraction = F32(1.5)print(typeof(small))print(small.to_int())print(fraction + F32(0.5))Fixed-width conversion and mixed arithmetic need care at boundaries. See current numeric limits before using them for representation-sensitive work. For an introductory program, use Int and Float.
Annotations
Section titled “Annotations”Use : Type on a binding initializer, parameter, or return declaration. Construction also checks field and enum-payload types. These are runtime checks, not a static type-checking pass.
let answer: Int = 42func label(value: Int): Str { ret "value: {value}" }print(label(answer))A binding annotation checks its initializer only; reassignment does not preserve the constraint. Type names in annotations are expressions resolving to type values, so let Number = Int can name a type without introducing new type identity.
Type declarations
Section titled “Type declarations”kind Name { field: Type, ... } declares a product with named fields. Construct it with Name { field: value, ... }, supplying all fields. enum Name { Variant(Type), Unit, ... } declares a sum with alternatives. type Name { func method(self): Type ... } declares an abstract interface.
kind Point { x: Int, y: Int }enum Message { Text(Str), Quit }
let point = Point { x: 3, y: 4 }let message = Message.Text("hello")print(point.x)print(message)A unit enum variant is constructed without a call, as Message.Quit. Its match pattern is Quit(). Fields and variant payloads can carry other types, subject to the current type-composition limits.
Generics
Section titled “Generics”Declare parameters with square brackets, as in kind Pair[A, B]. Apply them explicitly, as in Pair[Int, Str]. Opt[Int], Res[Int, Str], Arr[Int], and Map[Str, Int] are common library instantiations. The runtime does not infer missing type arguments from a constructor’s payload.
In an implementation pattern, @T binds a generic parameter: impl Pair[@A, @B] { ... }. A concrete pattern such as impl Pair[Int, Str] { ... } targets that specialization. Type declarations themselves use plain parameter names without @.
Tuples
Section titled “Tuples”(a, b) constructs an ordered tuple whose elements may have different types. Its type is Tup[A, B]. Access elements using .0, .1, and so on. () is an empty tuple, (a,) is a one-element tuple, and (a) only groups an expression. tuple.len() returns its number of elements.
let record = ("Ada", 42)let (name, score) = recordprint(record.0)print(typeof(record))print(score)Interfaces
Section titled “Interfaces”type defines required methods; impl Kind as Interface { ... } declares conformance and supplies behavior. In an expression, value as Interface creates an interface view after checking conformance. This is not a numeric cast.
Within an impl, self is the receiver value and Self denotes its type. Generic-interface validation is incomplete; declaration acceptance does not establish every substituted signature. See methods and interfaces for a complete example, and protocols for standard interfaces.