fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

array2

array2

array2(T:Any):hashable is[Private constructor][src]
array(length0, length1) -- two-dimensional immutable array

array provides two-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
two index parameters.
Precondition
pre
  safety: length0 ≥ 0
  safety: length1 ≥ 0
  safety: length0 *? length1 >=? 0

Type Parameters

T:Any[src]

Fields

length0 i64[src]
length1 i64[src]
base array T[src]
the underlying one dimensional array

multidimensional indices are mapped to one dimensional indices as follows:

[x,y] -> [x * length1 + y]

resulting in the order:

arr[0,0], arr[0,1], arr[0,2], ..., arr[1,0], arr[1,1], arr[1,2], ...,
arr[2,0], arr[2,1], arr[2,2], ...

Functions

as_string => String[Redefinition of  Any.as_string][src]
create a string representation of this array including all the string
representations of its contents, separated by ',' and enclosed in '['
and ']'. Arrays in inner dimensions are grouped using '[' and ']'.

redefines:

dynamic_apply(R:Any,F:Typed_Function R,f F) => R[Inherited from  Any][src]
dynamic_apply -- apply `f.call` to `Any.this`'s dynamic type and value

This can be used to perform operation on values depending on their dynamic
type.

Here is an example that takes a `Sequence Any` that may contain boxed values
of types `i32` and `f64`. We can now write a feature `get_f64` that extracts
these values converted to `f64` and build a function `sum` that sums them up
as follows:


dynamic_type => Type[Inherited from  Any][src]
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.

There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
enumerate2 => list (tuple i64 i64 T)[src]
get a list of tuples indices and elements in this array
index [ ](I:integer,i1 I,i2 I) => T[src]
index_pairs => Sequence (tuple i64 i64)[src]
all pairs of indices: (0,0), (0,1), (0,2), .. (length0-1, length1-1)
indices0 => interval i64[src]
indices range in first dimension
indices1 => interval i64[src]
indices range in second dimension
prefix $ => String[Inherited from  Any][src]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.
transpose => array2 T[src]
the transpose of the array

flips the array along its diagonal

Type Features

type.as_string => String[Inherited from  Type][src]
string representation of this type to be used for debugging.

result has the form "<name>", but this might change in the future

redefines:

type.create2(s Sequence (Sequence T)) => array2 T[src]
create an array2 from a Sequence of a Sequence of elements
type.dynamic_type => Type[Inherited from  Type][src]
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.

Note: Typechecking is undecidable when 'type' is a type, Mark B. Reinhold, 1989
see: https://dspace.mit.edu/bitstream/handle/1721.1/149366/MIT-LCS-TR-458.pdf?sequence=6

redefines:

type.equality(a array2 T,b array2 T) => bool[Redefinition of  property.equatable.type.equality][src]
equality of two arrays2 is true iff `a` and `b` have the same dimensions and for all
`i in indices0` and `j in indices1` we have `a[i][j] = b[i][j]`.

For performance, this will compare the length of the arrays first.

This is defined only if T : property.equatable, it will result in a compile-time panic
if this is not the case.
type.hash_code(a array2 T) => u64[Redefinition of  property.hashable.type.hash_code][src]
create hash code for this array2.

This should satisfy the following condition:

(T.equality a b) : (T.hash_code a = T.hash_code b)

This will result in a compile-time `panic` in case T : property.hashable does not hold.

The algorithm used here is a variation of (XXXHash)[https://xxhash.com] as used in
(Python's tuple)[https://github.com/python/cpython/blob/849a80ec412c36bbca5d400a7db5645b8cf54f1f/Objects/tupleobject.c#L305]:

we start with a constant `hash_prime1`
for each value:
we take its hash code * `hash_prime2` and add it
then we rotate by `hash_rotate`
and multiply by `hash_prime3`
type.infix :(T:Any) => bool[Inherited from  Type][src]
Is this type assignable to a type parameter with constraint `T`?

The result of this is a compile-time constant that can be used to specialize
code for a particular type.


it is most useful in conjunction with preconditions or `if` statements as in


or

type.lteq(a array2 T,b array2 T) => bool[src]
NOT implemented, calling this fails at compile time

There is no natural total ordering for two-dimensional arrays
type.name => String[Inherited from  Type][src]
name of this type, including type parameters, e.g. 'option (list i32)'.
type.new(I:integer,length0 I,length1 I,init Binary T I I) => array2 T[src]
array(length0, length1) -- two-dimensional immutable array

array provides two-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
two index parameters.
type.prefix $ => String[Inherited from  Type][src]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913

redefines:

type.type_value => Type[Inherited from  Any][src]
Get a type as a value.

This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.

`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.

Applicable universe features

These are features in universe, that have an argument with a type constraint that matches this features type and can therefore be used with it.
equals(T:property.equatable,a T,b T) => bool[src]
equals -- feature that compares two values using the equality relation
defined in their type
hash(T:property.hashable,a T) => u64[src]
hash of a value
infix !=(T:property.equatable,a T,b T) => bool[src]
infix = -- infix operation as shorthand for 'equals'
infix =(T:property.equatable,a T,b T) => bool[src]
infix = -- infix operation as shorthand for 'equals'
infix ∈(T:property.equatable,a T,s container.Set T) => bool[src]
is `a` contained in `Set` `s`?

This should usually be called using type inference as in

infix ∉(T:property.equatable,a T,s container.Set T) => bool[src]
is `a` not contained in `Set` `s`?

This should usually be called using type inference as in

memoize(MM:container.Mutable_Map T R,T:property.equatable,R:Any,f Unary R T) => Unary R T[src]
memoize `f`.
wraps f so that f will only be called once for every unique input.

The term "memoization" was coined by Donald Michie in 1968 and
is derived from the Latin word "memorandum" ("to be remembered"),
usually truncated as "memo" in American English, and thus carries
the meaning of "turning a function into something to be remembered".
https://en.wikipedia.org/wiki/Memoization

example:

0.099dev (GIT hash e2d5298d8107bb5fe79600fdb06a49bc75756344)
last changed: 2026-11-23