Special functions

Special functions are defined with a fun keyword and cannot be invoked directly.

destruct

Destructor is invoked before memory is freed. Can be used to make sure no weak references are pointing at an object, for example a container can clear the parent field of its items.

from_slice

fun from_slice<T> (slice : Slice<T>) : List<T> = List<T>.from slice

object Framebuffer =
    def create (images : List<Image>) = ...
    
let framebuffer = Framebuffer.create [color, depth]    

The array [color, depth] is converted to Slice<Image>, on which from_slice is invoked to produce a List<Image>.

get

let v = map[k]

Indexer getter.

get_ptr

if array[i].is_occupied then
    ...

Indexer getter that returns a pointer instead of an element itself. Is used to invoke struct methods and access fields.

get_mut_ptr

array[i].is_occupied = true

Same as get_ptr, but the resulting pointer is mutable.

hash

fun hash (x : bool) state =
    let i = if x then 1 else 0
    Kd.hash<i32> i state

Calculates the hash and writes the result to state.

def Kd.hash @impl (x : bool) state = ...

Internally, fun hash becomes a specialization for the generic declaration Kd.hash.

type bool
    fun hash state = ...       

Function can be defined as a method.

new

type WProcessImpl @cpp =
    fun new (path : String)

Constructor of an external type defined in C++.

set

map[k] = v

Indexer setter.

to_string

fun to_string (x : TextPos) = "${x.line}, ${x.char}"

Converts a value to a string.

def Kd.to_string @impl (x : TextPos) = "${x.line}, ${x.char}"

Internally, fun to_string becomes a specialization for the generic declaration Kd.to_string.

type TextPos
    fun to_string = "$line, $char"

Function can be defined as a method.