From 2b7ce615ec142374a63fa00b3de53dd24749e6d5 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 9 Oct 2020 01:56:12 -0400 Subject: [PATCH] notes --- 20200926010452-trans_flag.org | 6 ++++++ 20201007142751-python_typing.org | 24 +++++++++++++++++++++--- 20201008164835-structural_typing.org | 9 ++------- 20201009010321-static_type_checking.org | 1 + 20201009010657-nominal_typing.org | 10 ++++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 20200926010452-trans_flag.org create mode 100644 20201009010321-static_type_checking.org create mode 100644 20201009010657-nominal_typing.org diff --git a/20200926010452-trans_flag.org b/20200926010452-trans_flag.org new file mode 100644 index 0000000..2606364 --- /dev/null +++ b/20200926010452-trans_flag.org @@ -0,0 +1,6 @@ +#+title: Trans Flag + +* Colors +- Maya Blue :: Hex: =#55CDFC=, RGB: =(85, 205, 252)=, CMYK: =0.662, 0.186, 0, 0.011= +- White :: Hex: =#FFFFFF=, RGB: =(255, 255, 255)=, CMYK: =0, 0, 0, 0= +- Amaranth Pink :: Hex: =#F7A8B8=, RGB: =(247, 168, 184)=, CMYK: =0, 0.319, 0.255, 0.031= diff --git a/20201007142751-python_typing.org b/20201007142751-python_typing.org index 904fe50..9c4809a 100644 --- a/20201007142751-python_typing.org +++ b/20201007142751-python_typing.org @@ -1,10 +1,12 @@ #+title: Python Typing +#+LINK: pep https://www.python.org/dev/peps/pep-%s/ Python does not require nor enforce strict typing, and instead takes a dynamic approach using [[file:20201008164244-duck_typing.org][Duck Typing]]. -Optional [[file:20201008164835-structural_typing.org][Structural Typing]] support for Python is provided via type hints as -described in [[https://www.python.org/dev/peps/pep-0484/][PEP-484]]. +Optional [[file:20201009010321-static_type_checking.org][Static Type Checking]] support for Python is provided via type hints as +described in [[pep:0484][PEP-484]] (which covers [[file:20201009010657-nominal_typing.org][Nominal Typing]]) and expanded upon in [[pep:0544][PEP-544]] +(which covers [[file:20201008164835-structural_typing.org][Structural Typing]]). Variables, function arguments, and return values can have their types annotated, e.g. "variable x has type integer" or "function y takes a string and returns a @@ -22,4 +24,20 @@ program correctness. - Type hints do not guarantee purity. - Type hints are not checked at run-time. * Fun facts -- Python's =boolean= inherits from =int=, hence =True + True = 2=. +- Per [[pep:0285][PEP-285]], Python's =boolean= inherits from =int=, hence =True + True = 2=. +* Relevant PEPs +- [[pep:0482][PEP 482 -- Literature Overview for Type Hints]] +- [[pep:0483][PEP 483 -- The Theory of Type Hints]] +- [[pep:0484][PEP 484 -- Type Hints]] +- [[pep:0526][PEP 526 -- Syntax for Variable Annotations]] +- [[pep:0544][PEP 544 -- Protocols: Structural subtyping (static duck typing)]] +- [[pep:0557][PEP 557 -- Data Classes]] +- [[pep:0560][PEP 560 -- Core support for typing module and generic types]] +- [[pep:0561][PEP 561 -- Distributing and Packaging Type Information]] +- [[pep:0563][PEP 563 -- Postponed Evaluation of Annotations]] +- [[pep:0585][PEP 585 -- Type Hinting Generics In Standard Collections]] +- [[pep:0586][PEP 586 -- Literal Types]] +- [[pep:0589][PEP 589 -- TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys]] +- [[pep:0591][PEP 591 -- Adding a final qualifier to typing]] +- [[pep:0604][PEP 604 -- Allow writing union types as X | Y]] +- [[pep:0613][PEP 613 -- Explicit Type Aliases]] diff --git a/20201008164835-structural_typing.org b/20201008164835-structural_typing.org index 80f1ead..9421384 100644 --- a/20201008164835-structural_typing.org +++ b/20201008164835-structural_typing.org @@ -10,10 +10,5 @@ types are equivalent and whether a type is a subtype of another. --- https://en.wikipedia.org/wiki/Structural_type_system #+end_quote -* Benefits -** Easier reasoning -Types make it easier to reason about code, as they describe succinctly what a -function can do. If a function takes a single string as an argument and returns an integer, there's only so many things -** Error reduction -While types are not a substitute for testing, they do obviate a class of tests -that you have to write yourself. +Structural type systems can achieve [[file:20201009010321-static_type_checking.org][static]] [[file:20201008164244-duck_typing.org][Duck Typing]], in that a type's +structure is what determines its suitability, not its name. diff --git a/20201009010321-static_type_checking.org b/20201009010321-static_type_checking.org new file mode 100644 index 0000000..84a7df5 --- /dev/null +++ b/20201009010321-static_type_checking.org @@ -0,0 +1 @@ +#+title: Static Type Checking diff --git a/20201009010657-nominal_typing.org b/20201009010657-nominal_typing.org new file mode 100644 index 0000000..7ab87f8 --- /dev/null +++ b/20201009010657-nominal_typing.org @@ -0,0 +1,10 @@ +#+title: Nominal Typing + +#+begin_quote +Nominal typing means that two variables are type-compatible if and only if their +declarations name the same type. For example, in C, two struct types with +different names in the same translation unit are never considered compatible, +even if they have identical field declarations. + +--- https://en.wikipedia.org/wiki/Nominal_type_system +#+end_quote