Hacker News new | ask | show | jobs
by rbranson 5401 days ago
How is this different than creating an OddNumber and EvenNumber type that check their input in the constructor at run-time? That is the point of a type system.

Scala can make this really transparent and concise using an abstract class to implement most of the plumbing and implicit type conversion to automatically convert the contract enforcement types to and from the native types.

   case class EvenNumber(val x: Int) extends Contract[Int] {
      require(x % 2 != 0)
   }