Functional languages have the notion of lazy sequences, which are an abstraction of infinite sequences that are stored using a small, finite amount of memory. It would be wasteful to realize an entire infinite sequence before even using it. The basic idea is to only call the function that generates the sequence when needed, and cache the results. With lazy sequences, you don’t blow the stack and the elements in the sequence are not recalculated everytime.
I recently had to use the
WebBrowser .NET component in a project.
The control is essentially Internet Explorer embedded in a
Scala supports both abstract and parameterized types, which are essentially revamped generics (in Java) or templates (in C++).
First off, methods can be parameterized, in order to abstract a generic type which can be used by it.
apply method in companion objects is the best place to start.
Here’s an example from the implementation of the
List class in the Scala library.
1 2 3 4 5 6
Classes and traits can be parameterized as well.
In most languages, types are designed to reduce casting, which can be an expensive operation. Type systems also imply support for variance, i.e. covariance and contravariance.