Presentation is loading. Please wait.

Presentation is loading. Please wait.

Scala Overview Brandon Clopton CSCI 431. Scala fuses object-oriented and functional programming in a statically typed programming language. It is aimed.

Similar presentations


Presentation on theme: "Scala Overview Brandon Clopton CSCI 431. Scala fuses object-oriented and functional programming in a statically typed programming language. It is aimed."— Presentation transcript:

1 Scala Overview Brandon Clopton CSCI 431

2 Scala fuses object-oriented and functional programming in a statically typed programming language. It is aimed at the construction of components and component systems. Ideally, software should be assembled from libraries of pre-written components, just as hardware is assembled from pre-fabricated chips. Components in this sense are simply software parts which are used in some way by larger parts or whole applications. Components can take many forms; they can be modules, classes, libraries, frameworks, processes, or web services. Their size might range from a couple of lines to hundreds of thousands of lines. They might be linked with other components by a variety of mechanisms, such as aggregation, parameterization, inheritance, remote invocation, or message passing.

3 Scala programs resemble Java and C# programs in many ways and they can seamlessly interact with code written in Java. Everything can be nested, including classes. Hello World Example: object HelloWorld { def main(args: Array[String]) = { Console.println("Hello, world!"); }

4 Scala is a pure object-oriented language in the sense that every value is an object and every operation is a message send. Class abstractions are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance. Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. In particular, the type system supports: - generic classes, - variance annotations, - upper and lower type bounds, - inner classes and abstract types as object members, - compound types, - explicitly typed self references, - views, and - polymorphic methods.

5 object UnifiedTypes { def main(args: Array[String]): Unit = { val set = new scala.collection.mutable.HashSet[Any] set += "This is a string" // add a string set += 732 // add a number set += ’c’ // add a character set += true // add a boolean value set += &main // add the main function val iter: Iterator[Any] = set.elements while (iter.hasNext) { Console.println(iter.next.toString()) } Output: c true 732 This is a string Objects are objects!

6 def sqrts(xs: List[double]): List[double] = xs filter (0 <=) map Math.sqrt Scala is also a functional language in the sense that functions are first-class values. sqrts takes a list xs of double precision numbers, and returns a list consisting of the square roots of all non-negative elements of xs. The map method applies a given function uniformly to all sequence elements, yielding a sequence of the function results. The filter method applies a given predicate function to all sequence elements and returns a sequence of those elements for which the predicate is true.

7 References http://www.scala-lang.org/docu/files/ScalaOverview.pdf Questions?


Download ppt "Scala Overview Brandon Clopton CSCI 431. Scala fuses object-oriented and functional programming in a statically typed programming language. It is aimed."

Similar presentations


Ads by Google