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

  • 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.

主站蜘蛛池模板: 三江| 西华县| 临汾市| 读书| 上林县| 海伦市| 离岛区| 彝良县| 高淳县| 嫩江县| 渝北区| 永清县| 韶山市| 平塘县| 霍城县| 明水县| 当阳市| 武定县| 三都| 奉贤区| 婺源县| 老河口市| 会泽县| 孝感市| 大化| 韩城市| 绿春县| 沂水县| 长乐市| 海阳市| 建德市| 定襄县| 甘谷县| 砀山县| 泗阳县| 子洲县| 永康市| 阿拉善右旗| 汾阳市| 红河县| 汉源县|