Skip to content

Commit a623276

Browse files
committed
docs: Reword section about derived data types
We don't actually use the Newtype paradigm, which is required for trait-based type systems, but instead it's plain old type inheritance.
1 parent f649992 commit a623276

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/datatypes.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ In addition, SHC specifies some derived types of these builtin types with addtio
3232
- :class:`shc.interfaces.pulse.PulseVolumeComponents`
3333

3434

35-
.. _datatypes.newtype:
35+
.. _datatypes.semantic_derivation:
3636

37-
Newtype paradigm in SHC
38-
-----------------------
37+
Inherited semantic types in SHC
38+
-------------------------------
3939

40-
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>`_:
4142
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.
4344
A good example for this method are the different integer types for 0-100% ranges provided by SHC:
4445

4546
* :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
9091
9192
value = shc.conversion.from_json(json.loads(serialized_value), shc.datatypes.RangeFloat1)
9293

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>`).
9495
To add support for further types, :func:`shc.conversion.register_json_conversion` can be used to register the required converter functions.
9596

9697

0 commit comments

Comments
 (0)