Functional programming is a paradigm coming from the declarative programming. Despite what we can sometimes hear, the idea of functional programming is not new. In the late 1950s, Lisp paved the road for the yet to become large family of functional programming languages. It recently became popular again with the rise of big data and machine learning.
Scala is a general-purpose programming language that has been started in 2004 by Martin Odersky (EPFL). The language is inter-operable with Java and Java-like languages, and Scala executables run on the Java Virtual Machine (JVM). Like Java it has a strong static type system, but it does not require type declarations. Finally, Scala being younger than Java (1995), its design tries to solve some of the problems of Java.
Scala is a portmanteau of scalable and language, to reflect the fact that the language is designed to grow and easily integrate new features over time. There are pros and cons to this... For example it is easy to extend or add specific features from other languages, but then there is no guarantee for backward compatibility between Scala versions. In addition, the syntax of the language is not unique (many optional rules, like type hints).
Scala is not a pure functional programming language. It is multi-paradigm, including functional programming, imperative programming, object-oriented programming and concurrent computing.
-
Yes: A few functional programming concepts through examples in Scala.
-
No: be an expert in Scala.
We provide several images for the need of the exercise. We try to keep the size of the image as light as possible, and it is based on the alpine distribution (the image size is about 100 Mo). To play with the image, build it or download it:
# Go to the folder containing the Dockerfile
cd docker/alpine/
# Build the image - <name> can be scala/2.11.8 for example
docker build -t <name> .
# List the images - scala/2.11.8 should be there!
docker image ls
For the JI, we recommend to the users to clone the repo on their machine, and to download the Scala image:
IMAGE=gitlab-registry.in2p3.fr/maitresnageurs/quatrenages/scala:2.11.8
docker run --rm --tty --interactive --volume $PWD:/app ${IMAGE} scala
For convenience, you can define aliases to use the docker as if you were on your local directory directly. For example, to launch a Scala REPL (scala shell if you prefer) from your machine:
toto@local~:$ imageID="gitlab-registry.in2p3.fr/maitresnageurs/quatrenages/scala:2.11.8"
toto@local~:$ alias myscala='docker run --rm --tty --interactive --volume $PWD:/app ${imageID} scala'
toto@local~:$ myscala
Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_151).
Type in expressions for evaluation. Or try :help.
scala>
Obviously it runs from the docker, but you do not need to know it! Same trick can be use for the compiler
toto@local~:$ imageID="gitlab-registry.in2p3.fr/maitresnageurs/quatrenages/scala:2.11.8"
toto@local~:$ alias myscalac='docker run --rm --tty --interactive --volume $PWD:/app ${imageID} scalac'
toto@local~:$ myscalac whatever.scala # compile
toto@local~:$ myscala whatever.scala # or compile/execute directly
Finally, it is always a good idea to define aliases to avoid typing long command. We put a bash script with a few pre-define aliases in scripts/
. You can activate it by sourcing the script in there: source init.sh
. We encourage you to add new aliases!
Sorry, I have no idea how all of that works on Windows! If you tried, do not hesitate to report anything weird you encountered (or let me know if that works)!
We split the work in 3 parts (~40 min):
- Syntax review: A very brief overview of the Scala syntax (15 min).
- simple exercises: simple exercises to discover a few functional programming concepts and Scala (20 min).
- extensions: domain-specific languages (DSL) in Scala (5 min).