Component abstractions in Scala: the basics, part 2

And we’re back after only 5 minutes of break after Martin’s first talk. This really looks like work 🙂

And no time to relax, Martin is starting immediately with explaining the Scala Type system.

This supports three Top Types: Any, AnyRef and AnyVal are the base types, for respectively all, and all reference and all value types. Then there is Nothing, which is a subtype of all types and does not have any value. This type is useful to signal abnormal termination (throw new error of type Nothing) and as an element of empty collections. Taking an element of a List[Nothing] has type Nothing. The null value has a type too, this is type Null. Null is a subtype of all reference type, but not value types. Although null is included in the language, it is not often used, says Martin, usually it is replaced by Option.

After this implementation we get a live demo of Scala, because of the wobbly internet connection, not via http://www.simplyscala.com/ but on Martin’s own laptop. On of the things shown in the demo is that Scala has a map function very similar to C#: nums map (x => x+1). According to Martin C# stole this idea from Scala 🙂 Operations are performed on the highest type that applies, so performing an Update on a string works, since there is an Update on lists and a string is actually a list and string does not have an Update function. I am not sure whether this is also the case in Java (in C#, it is).

The functional operations (like map), which can be evaluated in a lazy way, by using m.view (similar to m.par which makes a function parallel) So the standard  way is non-lazy.

More Scala tomorrow, now it is time for cocktails 🙂