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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.191.134