Types
Supported types
Section titled “Supported types”| Type | Description | Literal examples |
|---|---|---|
Int | 32-bit signed integer | 42, 0xFF, 0b1010, 1_000 |
Long | 64-bit signed integer | 100L, 0xFFL, 9999999999L |
Double | 64-bit floating-point | 3.14, 2.5e10, 1.0f, -0.5 |
String | UTF-8 string | "hello", """raw""", "$x" |
Boolean | True or false | true, false |
Char | Single character | 'A', '\n' |
Unit | No meaningful value | Implicit void return |
Any | Top type (supertype of all types) | — |
null | Null reference | null |
Type inference
Section titled “Type inference”Skotch infers types from literal initializers:
val x = 42 // Intval pi = 3.14 // Doubleval s = "hello" // Stringval b = true // Booleanval n = null // nullExplicit type annotations are also supported:
val x: Int = 42val s: String = "hello"Double arithmetic
Section titled “Double arithmetic”Double supports all arithmetic operators, and mixed Int/Double
arithmetic promotes to Double:
fun main() { val a = 3.0 val b = 2.0 println(a + b) // 5.0 println(a * b) // 6.0 println(a / b) // 1.5 println(-2.5) // -2.5 println(1.0e2) // 100.0}Type annotations
Section titled “Type annotations”Function parameters require explicit types. Return types can be inferred for expression-body functions.
fun add(a: Int, b: Int) = a + b // return type Int inferredfun greet(name: String): String { // explicit return type return "Hello, $name"}Not yet supported
Section titled “Not yet supported”| Feature | Status |
|---|---|
Nullable operators (?., ?:, !!) | Implemented — safe calls, elvis, non-null assertion |
Type checks (is/!is) | Implemented — emits instanceof with JVM type descriptors |
| Smart casts | Implemented — when/if branch narrowing with checkcast + unbox for primitives |
Type casts (as/as?) | Parsed; safe cast (as?) returns null on failure |
Generics (T, List<Int>) | Implemented — type parameters, bounds, variance (in/out), star projection, reified |
Nothing | Implemented — bottom type, assignable to all types |
| Type aliases | Implemented — typealias erased to underlying type |
Char type | Implemented — Ty::Char with CharLit token, println('K') prints K, s[i] returns Char |