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

Summary

The type system is one of the key components of the Scala language. It allows the developer to express expectations about the behavior of the program, which can then be checked at compile time. This reduces the number of tests needed to verify the correctness of the solution and the possibility of runtime errors.

Usually, strictly typed languages are associated with verbose code. Normally, this is not the case with Scala because of its powerful type inference mechanism.

Scala allows you to define very narrow types containing a single value as well as much wider types, even those represented as a combination of other types.

The type definition can be made more precise by using type constraints, type parameters, and variance.

We also looked at some examples of how the type system can be used to express domain constraints.

Needless to say, Scala's ecosystem is much richer than what we have covered here. Some open source libraries offer advanced type constraints that are expressed as refined types, fixpoint types, or tagged types. Other libraries, such as shapeless, provide the possibility for type-level programming, which allows you to express and verify quite complex program logic at compile time.

主站蜘蛛池模板: 盘锦市| 高雄县| 将乐县| 彩票| 麻江县| 庄浪县| 鹿泉市| 昌江| 雷山县| 双城市| 同心县| 大英县| 革吉县| 湘潭县| 滦平县| 芦溪县| 阿克陶县| 渑池县| 吕梁市| 冀州市| 安溪县| 沅陵县| 潍坊市| 崇义县| 中方县| 梁山县| 宿迁市| 陆河县| 平凉市| 平遥县| 黄龙县| 西宁市| 乐东| 佛冈县| 潍坊市| 新绛县| 青龙| 盐池县| 沙湾县| 应城市| 开平市|