GithubHelp home page GithubHelp logo

a-tour-of-scala's Introduction

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. [...]

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.

~ 2bdb2


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 Base...

It's a couple of largish files designed to be presented in a lecture format, scrolling start to finish.

It covers:

  • Pattern matching
  • Scala function calling semantics
  • Scala implicit semantics
  • The typeclass pattern
  • Trait bound desugaring
  • Functor, Monad for commonly used types (e.g. R => ?, List, Option)
  • for notation desugaring
  • Monoid and Semigroup
  • Laziness
  • A stripped down effect monad (Sync)
  • State
  • Kleisli/ReaderT
  • Free
  • Validated
  • Applicative
  • FreeAp
  • Parser combinators

It does not yet cover:

  • OptionT and EitherT
  • Lenses
  • A proper reimplementation of Circe

...and given lectures about it!

Version 1

Version 2

Parser combinators


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.

^^ If you do want to learn functional programming from the ground up, I personally recommend Learn You a Haskell, or the QFPL Functional Programming + Applied Functional Programming courses.

Contributing

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.

Running

  • sbt run in the root directory

a-tour-of-scala's People

Contributors

maxwellbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

a-tour-of-scala

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.