Static typing is to a good programmer what a spell checker is to a good writer. – Peter Van Roy

Prelude

We would never do this

def add(a: Any, b: Any) = ???

or would we 😉

def add(a, b):
    # Adding two values the Python way
    return a + b

Static Typing

We have chosen a typed language that enforces some restrictions at compile time

def add(a: Int, b: Int): Int = a + b

val foo: String = "foo"

add(foo, 2) // type error

I think we can all agree that this is a sane thing to do.

But can we do better?

Almost good enough

case class Point(latitude: Double, longitude: Double)

which superficially seems good enough until

val lat = 42.0
val lng = -10.0

val point = Point(lng, lat)
def fireNukeAt(point: Point): Unit == ???

The compiler can't help us in this case

Value Classes