- Functional Python Programming
- Steven F. Lott
- 230字
- 2021-08-27 19:20:23
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.
- 編程的修煉
- Getting Started with ResearchKit
- Koa開發:入門、進階與實戰
- GeoServer Beginner's Guide(Second Edition)
- Python算法從菜鳥到達人
- Web Development with MongoDB and Node(Third Edition)
- 常用工具軟件立體化教程(微課版)
- PLC應用技術(三菱FX2N系列)
- Machine Learning in Java
- RealSenseTM互動開發實戰
- Python 3 數據分析與機器學習實戰
- Node.js從入門到精通
- .NET 4.0面向對象編程漫談:應用篇
- 面向物聯網的Android應用開發與實踐
- CISSP in 21 Days(Second Edition)