On Sat, Feb 1, 2020 at 10:06 AM <[email protected]> wrote:
>
> The types in most programming languages are only technical types. If a
> variable has a type, you may know that it is of type integer or double, but
> you don't know if it's a length or an area.
> The types required are semantic types.
>
> stypes:
> length
> area
> time
> speed
> scalar
>
> allowed expressions:
> length = length
> length + length : length
> time = time
> time + time : time
> scalar * length : length
> scalar * time : time
> sqrt(area) : length
> speed = speed
> length / time : speed
>
This doesn't need a dedicated type system. Those are actual types,
representing units - though you've omitted the actual units. Create a
system of classes with actual units, for instance:
class Meter(int):
...
class Second(int):
...
Define the operations that are valid on each of these, and what they
return. Define the valid comparisons (for instance, 3 meters is not
less than 4 seconds, and that doesn't make sense).
Python's normal type system is quite powerful, and can handle this smoothly.
(Once you've had a shot at building this yourself, poke around on PyPI
and see what already exists.)
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/4B3G6IVV7GZEP4LSEZAL6FWON4KAWVJO/
Code of Conduct: http://python.org/psf/codeofconduct/