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

  • Learn Scala Programming
  • Slava Schmidt
  • 199字
  • 2021-06-10 19:35:47

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.

主站蜘蛛池模板: 疏勒县| 紫云| 永济市| 平顺县| 南江县| 平和县| 前郭尔| 张家口市| 贺兰县| 沁阳市| 霍城县| 白城市| 祁阳县| 竹山县| 洛南县| 西昌市| 临洮县| 凤阳县| 泌阳县| 安岳县| 诸城市| 色达县| 宝丰县| 龙川县| 板桥市| 河北区| 左云县| 三河市| 会同县| 龙泉市| 讷河市| 威宁| 博湖县| 临湘市| 永新县| 沿河| 开平市| 泰顺县| 巴里| 新闻| 望谟县|