You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To make :ref:`type checking and automatic type conversions <base.typing>` more useful, SHC makes use of the "Newtype" paradigm (known e.g. from `Haskell <https://wiki.haskell.org/Newtype>`_ and `Rust <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction>`_):
40
+
To make :ref:`type checking and automatic type conversions <base.typing>` more useful, SHC makes use of type inheritance for semantic purposes.
41
+
This is similar to how the "Newtype" paradigm is used in `Haskell <https://wiki.haskell.org/Newtype>`_ or `Rust <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction>`_:
41
42
When a Connectable object's values have special additional semantics, a derived type is used instead of the plain scalar type to specify these semantics.
42
-
This allows the type checking to check for mismatched value semantics of connected objects (even with the same scalar type) and to chose the correct type converstion automatically.
43
+
This allows the type checking to check for mismatched value semantics of connected objects (even with the same scalar type) and to chose the correct type conversion automatically.
43
44
A good example for this method are the different integer types for 0-100% ranges provided by SHC:
44
45
45
46
* :class:`RangeUInt8 <shc.datatypes.RangeUInt8>` is derived from `int` and its instances shall be values from 0 (0%) to 255 (100%)
@@ -90,7 +91,7 @@ Similar to the default converters, the :mod:`shc.conversion` module provides a g
90
91
91
92
value = shc.conversion.from_json(json.loads(serialized_value), shc.datatypes.RangeFloat1)
92
93
93
-
The two converters natively support simple builtin types, Enums and NamedTuples by default, as well as any derived types from these (e.g. for :ref:`Newtypes <datatypes.newtype>`).
94
+
The two converters natively support simple builtin types, Enums and NamedTuples by default, as well as any derived types from these (e.g. for :ref:`semantic derived types <datatypes.semantic_derivation>`).
94
95
To add support for further types, :func:`shc.conversion.register_json_conversion` can be used to register the required converter functions.
0 commit comments