Prelude

Module prelude

import prelude

The types, attributes and values that are always in scope.

prelude is imported into every module automatically. It defines the built-in types the runtime provides, the attributes that describe what a value can do, and the two unions — Option and Result — that the rest of the standard library returns.

Nothing here has to be imported, and nothing here can be avoided: Int, String, Array and the rest are prelude declarations, and the for element <- value loop is a call into Iterable.

Contents


Unions

Number

`prelude/shim.zirr:61`
union Number {
	Float
	Int
}

Cases

Case Interpretation
Float A floating point number.
Int A whole integer number.

Option

`prelude/option.zirr:21`
union Option {
	Some
	None
}

An option type that can be either Some or None.
Used for values that may or may not be present.

Cases

Case Interpretation
Some The present value.
None The absent value.

Result

`prelude/result.zirr:26`
union Result {
	Ok
	Err
}

A result type that can be either Ok or Err.
Used for functions that can fail.

Cases

Case Interpretation
Ok The successful result.
Err The error result.

Data

ClosedRange

`prelude/iterable.zirr:14`
data ClosedRange {
	start: Int
	end: Int
}

Represents a closed range of integers from start (inclusive) to end (inclusive).

Fields

Field Description
start
end

Err

`prelude/result.zirr:48`
data Err {
	reason
}

The error result.

Fields

Field Description
reason The failure reason

None

`prelude/option.zirr:31`
data None

The absent value.


Ok

`prelude/result.zirr:29`
data Ok {
	value
}

The successful result.

Fields

Field Description
value The value of the successful result.

OpenRange

`prelude/iterable.zirr:22`
data OpenRange {
	start: Int
	end: Int
}

Represents an open range of integers strictly between start and end (both exclusive).

Fields

Field Description
start
end

Pair

`prelude/iterable.zirr:28`
data Pair {
	key
	value
}

A key/value pair, as yielded when iterating a Dict.

Fields

Field Description
key
value

Range

`prelude/iterable.zirr:6`
data Range {
	start: Int
	end: Int
}

Represents an open range of integers from start (inclusive) to end (exclusive).

Fields

Field Description
start
end

Some

`prelude/option.zirr:24`
data Some {
	value
}

The present value.

Fields

Field Description
value The value that is present.

Attributes

AnyOption

`prelude/option.zirr:12`
attr AnyOption {
	toOption(self: @AnyOption) -> Option
}

Marks a union as an option type, and says how to read one as an Option.
Types annotated with @AnyOption are expected to be unions that follow the
Some/None pattern, or to convert themselves into one. This is what ?. and
?? read a value through when it is not already a Some or a None, so
annotating a union of your own is what makes those operators work on it.

Write it on each member type as well as on the union: a union’s attributes
are not read off a value of one of its members, which is why Option
annotates Some and None individually.

Fields

Field Description
toOption Returns this value as an Option, which for a union already shaped like one is the value itself.

AnyResult

`prelude/result.zirr:17`
attr AnyResult {
	toResult(self: @AnyResult) -> Result
}

Marks a union as a result type, and says how to read one as a Result.
Types annotated with @AnyResult are expected to be unions that follow the
Ok/Err pattern, or to convert themselves into one. This is what !. and
!! read a value through when it is not already an Ok or an Err.

Write it on each member type as well as on the union, the way this module
annotates Ok and Err individually: a union’s attributes are not read off
a value of one of its members.

Fields

Field Description
toResult Returns this value as a Result, which for a union already shaped like one is the value itself.

Countable

`prelude/attributes.zirr:29`
attr Countable {
	length(value: @Countable) -> Int
}

Marks a type as countable, providing a way to get its length.

Fields

Field Description
length Returns the length of a value.

Default

`prelude/attributes.zirr:5`
attr Default {
	value
}

Transparently indicates the assumed default value of a parameter or field.
Can be used by tooling and libraries.

Fields

Field Description
value The default value for a parameter.

Deprecated

`prelude/attributes.zirr:12`
attr Deprecated {
	reason: String
}

Marks a declaration as deprecated with a reason.
IDEs and other tools can use this information to warn users about deprecated declarations.

Fields

Field Description
reason

Error

`prelude/result.zirr:4`
attr Error {
	debug(err) -> String
}

Marks a type as an error type.

Fields

Field Description
debug Returns a debug string representation of the error.

Iterable

`prelude/attributes.zirr:35`
attr Iterable {
	iterate(value: @Iterable, yield: fn(Any) -> Bool)
}

Marks a type as iterable, allowing for element <- value.

Fields

Field Description
iterate Calls yield with each element, stopping early if yield returns false.

Numeric

`prelude/attributes.zirr:17`
attr Numeric {
	toNumber(value: @Numeric) -> Number
}

Marks a declaration as numeric, providing a way to convert it to a number.

Fields

Field Description
toNumber A function to convert the value to a number.

Printable

`prelude/attributes.zirr:23`
attr Printable {
	toString(self: @Printable) -> String
}

Marks a type as printable, providing a way to convert it to a string.

Fields

Field Description
toString A function to convert the value to a string.

Types

Any

`prelude/shim.zirr:4`
extern type Any

Anything is a value of type Any.


AnyModule

`prelude/shim.zirr:14`
extern type AnyModule

All modules are of type AnyModule.


AnyType

`prelude/shim.zirr:6`
extern type AnyType

All types are of type AnyType.


Array

`prelude/shim.zirr:23`
extern type Array

A finite list of values.


Attribute

`prelude/shim.zirr:9`
extern type Attribute

All attributes are of type Attribute.


AttributeType

`prelude/shim.zirr:11`
extern type AttributeType

All attribute types are of type AttributeType.


Binary

`prelude/shim.zirr:80`
extern type Binary

A sequence of raw bytes.
Can be indexed and iterates over Byte.


Bool

`prelude/shim.zirr:30`
extern type Bool

Represents boolean values like True and False.
Typically used for conditionals and flags.


Byte

`prelude/shim.zirr:83`
extern type Byte

A single byte.


Char

`prelude/shim.zirr:33`
extern type Char

A single character from a string.


Dict

`prelude/shim.zirr:40`
extern type Dict {
	keys: Array
}

An associative array of keys and their values.
Can be indexed by keys.
Iterates over Pair.


Float

`prelude/shim.zirr:55`
extern type Float

A floating point number.


Func

`prelude/shim.zirr:46`
extern type Func {
	name: String
	arity: Int
}

A callable function.


Int

`prelude/shim.zirr:59`
extern type Int

A whole integer number.


ModuleType

`prelude/shim.zirr:16`
extern type ModuleType

All module types are of type ModuleType.


String

`prelude/shim.zirr:72`
extern type String {
	chars: [Char]
}

A regular String.
Can be indexed to get the Byte.
Iterates over Char.


Void

`prelude/shim.zirr:88`
extern type Void

The type of the void value.


Functions

append

`prelude/shim.zirr:18`
extern fn append(Array, Any) -> Array

len

`prelude/countable.zirr:3`
fn len(v: @Countable) -> Int

panic

`prelude/shim.zirr:91`
extern fn panic(message: String) -> Void

Terminates execution with the given message.


Constants

false

`prelude/shim.zirr:26`
const false

true

`prelude/shim.zirr:25`
const true

void

`prelude/shim.zirr:86`
extern const void: Void

Represents the absence of a value.