Module: Kumi::Core::Types
- Defined in:
- lib/kumi/core/types.rb,
lib/kumi/core/types/system.rb,
lib/kumi/core/types/profile.rb,
lib/kumi/core/types/registry.rb,
lib/kumi/core/types/inference.rb,
lib/kumi/core/types/dtype_rule.rb,
lib/kumi/core/types/normalizer.rb,
lib/kumi/core/types/value_objects.rb
Overview
The Types facade: the stable public surface for constructing and querying types. Construction and predicates live here; all type policy (promotion, categories, constraint compatibility) lives in Types::System, and the kind table + canonical-string parsing live in Types::Registry.
Defined Under Namespace
Modules: DtypeRule, Registry, ValueObjects Classes: ArrayType, Inference, Normalizer, Profile, ScalarType, System, TupleType, Type
Class Method Summary collapse
- .array(element_type) ⇒ Object
- .array?(dtype) ⇒ Boolean
-
.coerce(value, context:) ⇒ Object
Coerce a Type object or scalar-kind symbol into a Type object.
- .collection?(dtype) ⇒ Boolean
- .element_of(type) ⇒ Object
-
.infer_from_value(value) ⇒ Object
---- inference / policy -------------------------------------------------.
- .normalize(type_input) ⇒ Object
-
.parse(str) ⇒ Object
Parse the canonical string form back into a Type object (inverse of Type#to_s): "array
" -> ArrayType(ScalarType(:integer)). -
.promote(*types) ⇒ Object
Convenience delegates to the default type-system policy.
-
.scalar(kind) ⇒ Object
---- constructors -------------------------------------------------------.
- .tuple(element_types) ⇒ Object
- .tuple?(dtype) ⇒ Boolean
- .unify(left, right) ⇒ Object
- .valid_type?(type) ⇒ Boolean
Class Method Details
.array(element_type) ⇒ Object
39 40 41 |
# File 'lib/kumi/core/types.rb', line 39 def self.array(element_type) ArrayType.new(coerce(element_type, context: "array element")) end |
.array?(dtype) ⇒ Boolean
23 24 25 |
# File 'lib/kumi/core/types.rb', line 23 def self.array?(dtype) dtype.is_a?(ArrayType) end |
.coerce(value, context:) ⇒ Object
Coerce a Type object or scalar-kind symbol into a Type object.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kumi/core/types.rb', line 73 def self.coerce(value, context:) case value when Type then value when Symbol raise ArgumentError, "#{context} must be a known scalar kind, got #{value.inspect}" unless Registry.kind?(value) ScalarType.new(value) else raise ArgumentError, "#{context} must be a Type or scalar kind, got #{value.inspect}" end end |
.collection?(dtype) ⇒ Boolean
15 16 17 |
# File 'lib/kumi/core/types.rb', line 15 def self.collection?(dtype) tuple?(dtype) || array?(dtype) end |
.element_of(type) ⇒ Object
70 |
# File 'lib/kumi/core/types.rb', line 70 def self.element_of(type) = System.default.element_of(type) |
.infer_from_value(value) ⇒ Object
---- inference / policy -------------------------------------------------
63 64 65 |
# File 'lib/kumi/core/types.rb', line 63 def self.infer_from_value(value) Inference.infer_from_value(value) end |
.normalize(type_input) ⇒ Object
57 58 59 |
# File 'lib/kumi/core/types.rb', line 57 def self.normalize(type_input) Normalizer.normalize(type_input) end |
.parse(str) ⇒ Object
Parse the canonical string form back into a Type object (inverse of
Type#to_s): "array
53 54 55 |
# File 'lib/kumi/core/types.rb', line 53 def self.parse(str) Registry.parse(str) end |
.promote(*types) ⇒ Object
Convenience delegates to the default type-system policy.
68 |
# File 'lib/kumi/core/types.rb', line 68 def self.promote(*types) = System.default.promote(*types) |
.scalar(kind) ⇒ Object
---- constructors -------------------------------------------------------
33 34 35 36 37 |
# File 'lib/kumi/core/types.rb', line 33 def self.scalar(kind) raise ArgumentError, "unknown scalar kind: #{kind.inspect}" unless Registry.kind?(kind) ScalarType.new(kind) end |
.tuple(element_types) ⇒ Object
43 44 45 46 47 |
# File 'lib/kumi/core/types.rb', line 43 def self.tuple(element_types) raise ArgumentError, "tuple expects an array of types, got #{element_types.class}" unless element_types.is_a?(Array) TupleType.new(element_types.map { |t| coerce(t, context: "tuple element") }) end |
.tuple?(dtype) ⇒ Boolean
19 20 21 |
# File 'lib/kumi/core/types.rb', line 19 def self.tuple?(dtype) dtype.is_a?(TupleType) end |