官术网_书友最值得收藏!

Functional type systems

Some functional programming languages, such as Haskell and Scala, are statically compiled, and depend on declared types for functions and their arguments. To provide the kind of flexibility Python already has, these languages have sophisticated type-matching rules so that a generic function can be written, which works for a variety of related types.

In Object-Oriented Python, we often use the class inheritance hierarchy instead of sophisticated function type matching. We rely on Python to dispatch an operator to a proper method based on simple name-matching rules.

Since Python already has the desired levels of flexibility, the type matching rules for a compiled functional language aren't relevant. Indeed, we could argue that the sophisticated type matching is a workaround imposed by static compilation. Python doesn't need this workaround because it's a dynamic language.

Python 3 introduces type hints. These can be used by a program like mypy to discern potential problems with type mismatches. Using type hints is superior to using tests such ase  assert isinstance(a, int) to detect whether an argument value for the a parameter is an int. An assert statement is a runtime burden. Running mypy to validate the hints is generally part of ordinary quality assurance. It's a common practice to run mypy and pylint along with unit tests to confirm that software is correct.

主站蜘蛛池模板: 军事| 海丰县| 渝中区| 兴和县| 静安区| 从江县| 崇信县| 庆安县| 界首市| 黄冈市| 双柏县| 寻甸| 同江市| 景谷| 兴宁市| 谷城县| 常山县| 扎兰屯市| 光泽县| 甘孜| 罗田县| 翼城县| 滦南县| 额敏县| 多伦县| 峡江县| 玛曲县| 逊克县| 大名县| 南康市| 原平市| 东安县| 永胜县| 建平县| 岱山县| 龙南县| 金坛市| 夏河县| 甘肃省| 苗栗市| 克什克腾旗|