A tour of Scala
Scala is what happens when somebody takes OCaml, mixes in some Haskell, adds some Java coloured sprinkles in the mix, and and randomly shoves the whole thing together into a garbage disposal and lights it before running away laughing maniacally.
Which is to say, Scala is a bipolar, flawed, genius with a massive ego and huge ambitions. It is both utterly brilliant and utterly terrible at the same time, with the "Utterly Brilliant" shining more brightly. It is perhaps the programming language equivalent of Roman Polanski.
More precisely, Scala is a functional programming language more closely related to SML or Ocaml, with some improvements to support something resembling Haskell style typeclasses and monadic programming that were, perhaps, completely by accident.
It can be used surprisingly effectively as an imperative object orientated language, but it's a functional programming language at heart, and this is where its power lies.
Over the last 3 years, there've been times where I've needed to explain various functional concepts as they exist in Scala. Typically, all that functional goodness is locked up in libraries like Cats and Scalaz. Unfortunately, these libraries are labyrinthine - a tall tower of abstractions, obscured by hacks to improve syntax ergonomics and performance. Their source code is nothing like the quite readable Base package of Haskell.
So recently I've:
Implemented a Scala-flavoured
It's a couple of largish files designed to be presented in a lecture format, scrolling start to finish.
- Pattern matching
- Scala function calling semantics
- Scala implicit semantics
- The typeclass pattern
- Trait bound desugaring
Monadfor commonly used types (e.g.
R => ?,
- A stripped down effect monad (
- Parser combinators
It does not yet cover:
- A proper reimplementation of
...and given lectures about it!
This project is not an attempt to teach functional programming from the ground up^^ - rather an attempt to teach developers who might need to briefly contribute to Scala production codebases just enough to get by. It's also designed to be a useful as a 1-on-1 teaching tool, allowing the quick creation of example code and demos, where all abstractions can be copy-pasted into the snippet or Gist after a couple
Go to definitions.
^ I've had to make some things simpler at the cost of expressiveness. An example includes
Alternative not extending
Applicative to prevent implicit resolution clashes. There are ways to prevent this from happening, but it's out of scope for this kind of tutorial.
Feel free to contribute! If there's an abstraction that you think would be useful to document in here, open a PR. I intended on this being a useful teaching tool for any team, so that individuals can pick and choose the content they want to cover.
sbt runin the root directory