Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to write correct Scala programs

How to write correct Scala programs

Scala, because of its functional nature, already gives us some design tools to write correct programs: type polymorphism, higher-order functions, immutability, and others. There are also many test frameworks that allow us to detect some bugs. This is a good start, but we can do more: proving the absence of bugs. In this talk I will show how to use Isabelle, a proof assistant, to implement algorithms, prove them correct, and compile them as Scala programs. We’ll see how to formulate universal properties on programs and how to check them.

Avatar for Lars Hupel

Lars Hupel

August 21, 2025
Tweet

More Decks by Lars Hupel

Other Decks in Programming

Transcript

  1. Property testing is great! • ScalaCheck came out ~2007 •

    Use is pervasive now • A few alternatives exist: scalaprops, hedgehog
  2. Some things are hard with property testing • Anything with

    a large parameter space • Anything stateful • Anything with graphs
  3. scala> prop.check() ! Falsified after 0 passed tests. > ARG_0:

    1 > ARG_1: 2147483647 > ARG_0_ORIGINAL: 39501542
  4. What about this one? private void pushRun( int runBase, int

    runLen ) { this.runBase[stackSize] = runBase; this.runLen[stackSize] = runLen; StackSize++; }
  5. What about this one? private void pushRun( int runBase, int

    runLen ) { this.runBase[stackSize] = runBase; this.runLen[stackSize] = runLen; StackSize++; }
  6. Isabelle • Proof assistant for various logics • Typically: Higher-Order

    Logic (HOL) • Fully-fledged programming language and IDE