Browse documentation
Language

Type inspection

Inspect concrete runtime types and homogeneous scalar, array or Tensor storage datatypes without guessing mixed collection contents.

Aner provides import free built ins to inspect a value's concrete runtime type and its scalar or homogeneous element storage datatype. Inspection returns a String name; it does not convert the value, narrow its static type, or traverse collection contents.

Concrete runtime type

type(value) and type_of(value) are equivalent. They report the concrete runtime type retained inside Any, including a user defined class specialization or a typed array specialization. Null is reported as "null". Unit is not an Any payload and cannot be passed to either built in.

aner
let values = List(10, "sample", true, null)
print(type(values))        // List
print(type(values.get(0))) // Int64
print(type_of(values.get(1))) // String
print(type(null))          // null

The result is a name, rather than a type object. It cannot be supplied as a dynamic type argument or used to call a constructor by name. Runtime type inspection does not enable member access on an Any expression. Use a checked cast when a concrete static type is required:

aner
let value: Any = "  sample  "
if type(value) == "String" {
    print(cast<String>(value).trim())
}

cast<Type>(value) verifies the concrete type and does not perform a numeric or text conversion. A mismatch reports the existing cast diagnostic R1002.

Element storage datatype

dtype(value) reports the scalar datatype of a supported scalar, the declared homogeneous element datatype of a typed array, or the actual storage precision of a Tensor. A heterogeneous core collection reports "Any" even if its current elements all happen to have one type. The result is independent of collection contents and length.

Valuetype(value)dtype(value)
42Int64Int64
3.5Float64Float64
trueBoolBool
"sample"StringString
List(1, 2)ListAny
An empty DictionaryDictionaryAny
Set("a", "b")SetAny
Array<Int64>(2, 0)Array<Int64>Int64
DynamicArray<Float64>(4)DynamicArray<Float64>Float64
NDArray<Bool>(List(2, 3), false)NDArray<Bool>Bool
Bytes.from_hex("ff")BytesUInt8
Range(3)RangeInt64
A Float32 TensorTensorFloat32
A Float64 TensorTensorFloat64
aner
let numbers = DynamicArray<Float64>(capacity: 4)
numbers.append(1.5)
print(type(numbers))  // DynamicArray<Float64>
print(dtype(numbers)) // Float64
print(dtype(List(1, 2))) // Any

For a Tensor, dtype reports actual storage precision after any explicit transfer or configured execution policy. It does not report a requested precision, a compute accumulation precision, a device, or an inferred class label type. Native Tensor dtype accessors and typed array .dtype() methods remain available.

dtype accepts an Any argument so it can inspect dynamically stored supported values. Null, user defined objects, and opaque native values without a homogeneous scalar storage datatype produce R3202. Unit is rejected by the checker. dtype never guesses a schema for a Dictionary, a neural network, a Dataset, or a credential reference. Calendar values, Duration, Optional, and Result<T, E> have no element storage datatype; use type for their concrete native type or generic specialization. Bytes reports UInt8 for its unsigned byte storage, and Range reports Int64 for its arithmetic sequence. UInt8 is not a new scalar or accepted Array dtype.

Signatures and complexity

Built inResultTimeAdditional space
type(value: Any)StringO(t), for t bytes in the returned type nameO(t) result.
type_of(value: Any)StringO(t), identical to typeO(t) result.
dtype(value: Any)StringO(1), metadata or tag inspectionO(1) bounded datatype name.

These bounds describe inspection after argument evaluation. Current interpreter evaluation can copy owned scalar or native payloads according to their existing value semantics. Inspection itself does not scan values, materialize a Tensor, transfer device memory, or change an object.

See the String reference, typed arrays, and Tensor reference for their respective storage and operation contracts. Run the type inspection example to observe mixed values and homogeneous storage.

Aner documentation · Reference and guides