Slide 7
Slide 7 text
Types
type Distance = Double
type Weight = Double
def addWeightWithoutTypes(a: Double, b: Double) = ???
def addWeightWithTypes(a: Weight, b: Weight) = ???
val (d1: Double, w1: Double) = (2.2, 87) // (distance, weight)
val (d2: Distance, w2: Weight) = (2.2, 87) // weight
addWeightWithoutTypes(d, w) // compiles and runs but is incorrect behavior
addWeightWithTypes(d, w) // compile time error preventing incorrect usage
Catches bugs at compile time
Readable code