Type System¶
The type system defines all available types in Viper. Type is the base class
with static accessors for primitive types.
When to use: Use types to define schemas, validate data, and create parameterized containers like vectors and maps.
Quick Start¶
from dsviper import Type, TypeVector, TypeMap, TypeOptional
# Primitive type constants
t_int = Type.INT64
t_str = Type.STRING
# Parameterized container types
t_vec = TypeVector(Type.STRING) # list of strings
t_map = TypeMap(Type.STRING, Type.INT64) # dict[str, int]
# Nested types
t_nested = TypeMap(Type.STRING, TypeVector(Type.FLOAT))
# Nullable type
t_opt = TypeOptional(Type.STRING)
Choosing the Right Type¶
Use Case |
Type Class |
Example |
|---|---|---|
Primitive value |
|
Built-in constants |
Homogeneous list |
|
|
Key-value mapping |
|
|
Nullable value |
|
|
Concurrent list |
|
|
Fixed-size tuple |
|
|
Base Class¶
A utility class to handle type representation. |
|
A class used to describe the name of a type. |
Primitive Types¶
A class used to represent the void type. |
|
A class used to represent the bool type. |
|
A class used to represent the uint8 type. |
|
A class used to represent the uint16 type. |
|
A class used to represent the uint32 type. |
|
A class used to represent the uint64 type. |
|
A class used to represent the int8 type. |
|
A class used to represent the int16 type. |
|
A class used to represent the int32 type. |
|
A class used to represent the int64 type. |
|
A class used to represent the float type. |
|
A class used to represent the double type. |
|
A class used to represent the string type. |
|
A class used to represent the blob type. |
|
A class used to represent the blob_id type. |
|
A class used to represent the commit_id type. |
|
A class used to represent the uuid type. |
Container Types¶
A class used to represent a vector<element_type> type. |
|
A class used to represent a set<element_type> type. |
|
A class used to represent a map<element_type> type. |
|
A class used to represent a xarray<element_type> type. |
|
A class used to represent an optional<element_type> type. |
Algebraic Types¶
A class used to represent a tuple<T0, ...> type. |
|
A class used to represent a vec<element_type, size> type. |
|
A class used to represent a mat<numeric_type, columns, rows> type. |
|
A class used to represent a variant<T0, ...> type. |
|
A class used to represent the any type. |
User-Defined Types¶
A class used to represent a struct type. |
|
A class used to describe the fields of a struct. |
|
A class used to represent a field for a struct. |
|
A class used to represent an enum type. |
|
A class used to represent a case for an enum type. |
|
A class used to describe the cases of an enum. |
Concept Types¶
A class used to represent a concept type. |
|
A class used to represent a club type. |
|
A class used to represent a key<element_type> type where element_type is a concept, club or any_concept. |
|
A class used to represent the any_concept type. |