Prelude
Module prelude
import prelude
| Module | prelude |
| Source | prelude/attributes.zirr, prelude/countable.zirr, prelude/iterable.zirr, prelude/module-docs.zirr, prelude/option.zirr, prelude/result.zirr, prelude/shim.zirr |
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,Option,Result - Data —
ClosedRange,Err,None,Ok,OpenRange,Pair,Range,Some - Attributes —
AnyOption,AnyResult,Countable,Default,Deprecated,Error,Iterable,Numeric,Printable - Types —
Any,AnyModule,AnyType,Array,Attribute,AttributeType,Binary,Bool,Byte,Char,Dict,Float,Func,Int,ModuleType,String,Void - Functions —
append,len,panic - Constants —
false,true,void
Unions
Number
`prelude/shim.zirr:65`
union Number {
Float
Int
}
Cases
| Case | Interpretation |
|---|---|
Float |
A floating point number. |
Int |
A whole integer number. |
Option
`prelude/option.zirr:15`
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:21`
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:18`
data ClosedRange {
start: Int
end: Int
}
The integers from start to end, both included, written [start, end].
ClosedRange(0, 3) iterates 0, 1, 2, 3. It is the only form that can name any non-empty span exactly, which is why ranges returns it.
Fields
| Field | Description |
|---|---|
start |
The first integer in the range. |
end |
The last integer in the range. |
Err
`prelude/result.zirr:43`
data Err {
reason
}
The error result.
Fields
| Field | Description |
|---|---|
reason |
The failure reason |
None
`prelude/option.zirr:25`
data None
The absent value.
Ok
`prelude/result.zirr:24`
data Ok {
value
}
The successful result.
Fields
| Field | Description |
|---|---|
value |
The value of the successful result. |
OpenRange
`prelude/iterable.zirr:29`
data OpenRange {
start: Int
end: Int
}
The integers strictly between start and end, both excluded, written (start, end).
OpenRange(0, 3) iterates 1, 2.
Fields
| Field | Description |
|---|---|
start |
The integer just before the range. |
end |
The integer just past the range. |
Pair
`prelude/iterable.zirr:37`
data Pair {
key
value
}
A key/value pair, as yielded when iterating a Dict.
Fields
| Field | Description |
|---|---|
key |
The key the entry is stored under. |
value |
The value stored under it. |
Range
`prelude/iterable.zirr:7`
data Range {
start: Int
end: Int
}
The integers from start up to but excluding end, written [start, end).
Range(0, 3) iterates 0, 1, 2. This is the form to reach for by default: it counts end - start values, so it pairs with a length.
Fields
| Field | Description |
|---|---|
start |
The first integer in the range. |
end |
The first integer past the range. |
Some
`prelude/option.zirr:18`
data Some {
value
}
The present value.
Fields
| Field | Description |
|---|---|
value |
The value that is present. |
Attributes
AnyOption
`prelude/option.zirr:7`
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:13`
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:30`
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 |
Why it is deprecated, and what to use instead. |
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:36`
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:18`
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:24`
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:25`
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:84`
extern type Binary
A sequence of raw bytes.
Can be indexed and iterates over Byte.
Bool
`prelude/shim.zirr:34`
extern type Bool
One of the two values true and false.
Typically used for conditionals and flags. Comparisons produce one, and if, for and &&/|| require one.
Byte
`prelude/shim.zirr:87`
extern type Byte
A single byte.
Char
`prelude/shim.zirr:37`
extern type Char
A single character from a string.
Dict
`prelude/shim.zirr:44`
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:59`
extern type Float
A floating point number.
Func
`prelude/shim.zirr:50`
extern type Func {
name: String
arity: Int
}
A callable function.
Int
`prelude/shim.zirr:63`
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:76`
extern type String {
chars: [Char]
}
A regular String.
Can be indexed to get the Byte.
Iterates over Char.
Void
`prelude/shim.zirr:92`
extern type Void
The type of the void value.
Functions
append
`prelude/shim.zirr:20`
extern fn append(collection, value)
Returns a new collection with value added to the end, leaving the original untouched.
An Array takes any value; a Binary takes a Byte or another Binary.
len
`prelude/countable.zirr:5`
fn len(v: @Countable) -> Int
The number of elements in a countable value, read through its Countable attribute.
Counts a String in characters, an Array in elements, a Dict in entries and a Binary in bytes.
panic
`prelude/shim.zirr:95`
extern fn panic(message: String) -> Void
Terminates execution with the given message.
Constants
false
`prelude/shim.zirr:30`
const false
The false value of type Bool.
true
`prelude/shim.zirr:28`
const true
The true value of type Bool.
void
`prelude/shim.zirr:90`
extern const void: Void
Represents the absence of a value.