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

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.

主站蜘蛛池模板: 陇川县| 临汾市| 永州市| 门源| 北碚区| 日照市| 星子县| 北川| 卫辉市| 温州市| 文安县| 绩溪县| 古丈县| 子长县| 汉中市| 德江县| 招远市| 祁连县| 江永县| 美姑县| 宁陵县| 花垣县| 洛扎县| 历史| 清原| 宝清县| 武鸣县| 册亨县| 沾化县| 突泉县| 贵南县| 拉萨市| 松溪县| 东山县| 博客| 清镇市| 英山县| 微山县| 通州区| 平泉县| 三亚市|