Slide 1

Slide 1 text

@folone @xeno_by @adriaanm @retronym @extempore2

Slide 2

Slide 2 text

About me: @folone likes types* *same reasons why @propensive does in his “Batshit crazy algebra with types” talk

Slide 3

Slide 3 text

12 hours of audio every minute 300 million people every month

Slide 4

Slide 4 text

Stop… Hackertime!

Slide 5

Slide 5 text

42.type $ git clone [email protected]:folone/scala.git -b scalaexchange $ ant publish-local-opt -Dmaven.version.suffix="-typelevel"

Slide 6

Slide 6 text

1. Ranged

Slide 7

Slide 7 text

2. Residue

Slide 8

Slide 8 text

3. Records

Slide 9

Slide 9 text

Consistency

Slide 10

Slide 10 text

Here’s what you can do in Scala scala> val x = "panda!" x: String = panda! scala> val t: x.type = x t: x.type = panda! scala> final val k = "panda!" k: String("panda!") = panda!

Slide 11

Slide 11 text

Here’s what you cannot scala> val t: "panda!".type = "panda!" :1: error: identifier expected but string literal found. val t: "panda!".type = "panda!" ^

Slide 12

Slide 12 text

scala> val t: "panda!".type = "panda!" t: "panda!".type = panda! With 42.type

Slide 13

Slide 13 text

scala> val x = 42 x: Int = 42 scala> val t: x.type = 42 :8: error: type mismatch; found : x.type (with underlying type Int) required: AnyRef val t: x.type = 42 ^ scala> val workaround = Witness(42) workaround: shapeless.Witness{type T = Int(42)} = fresh$macro$3$1@35b45d3f scala> val t: workaround.T = 42 t: workaround.T = 42 Even more

Slide 14

Slide 14 text

scala> val t: 42.type = 42 t: 42.type = 42 scala> val t: 42 = 42 t: 42.type = 42 Or even Solution with 42.type

Slide 15

Slide 15 text

SimpleType ::= Path ‘.’ type A singleton type is of the form p.type, where p is a path pointing to a value expected to conform to scala.AnyRef. Before

Slide 16

Slide 16 text

After | Literal [‘.’ type] SimpleType ::= Path ‘.’ type

Slide 17

Slide 17 text

History

Slide 18

Slide 18 text

Quiz Literal-based singleton types in scala have seen their first implementation in: 2013 2011 2008 2004

Slide 19

Slide 19 text

http://existentialtype.net/2008/07/21/literally-dependent-types/ Quiz Literal-based singleton types in scala have seen their first implementation in: 2013 2011 2008 2004

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

State of deptypes Scala “Scala vs Idris: Dependent Types, Now and in the Future”* *Edwin Brady & Miles Sabin, Strange Loop 2013

Slide 22

Slide 22 text

How can we make it better? Well, we can try. Scala + SMT-solver

Slide 23

Slide 23 text

You would do way better to implement the [typechecking] logic completely externally to the compiler and use it as a black box from the compiler, then you might have a chance.

Slide 24

Slide 24 text

scala> import z3.scala._, z3.scala.dsl._ import z3.scala._ import z3.scala.dsl._

Slide 25

Slide 25 text

scala> findAll((x: Val[Int]) => x > 23 && x < 42).toList res0: List[Int] = List(24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41)

Slide 26

Slide 26 text

((x: Val[Int]) => x > 23 && x < 42)

Slide 27

Slide 27 text

((x: Int) => x > 23 && x < 42)

Slide 28

Slide 28 text

((x: Int) => x > 23 && x < 42).type

Slide 29

Slide 29 text

val magic: ((x: Int) => x > 23 && x < 42).type = 30

Slide 30

Slide 30 text

val magic: ((x: Int) => x > 23 && x < 42).type = 30 val x: 42 = 42 val x: ((x: Int) => x == 42).type = 42

Slide 31

Slide 31 text

val x: 42 = 42 val x: ((x: Int) => x == 42).type = 42 val x: Int = 42 val x: ((x: Int) => true).type = 42 val magic: ((x: Int) => x > 23 && x < 42).type = 30

Slide 32

Slide 32 text

But <: ((x: Int) => x > 10).type ((x: Int) => x > 23).type is

Slide 33

Slide 33 text

Liquid Types

Slide 34

Slide 34 text

L og i cally qu al i fie d Types

Slide 35

Slide 35 text

bit.ly/42_type

Slide 36

Slide 36 text

this thing would not be possible without: @xeno_by, @adriaanm, @retronym, and initial impl by @paulp Scala Z3 bindings: LARA@EPFL Z3: Microsoft research slides, illustrations: @killnicole Credits:

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Thanks. Questions? [email protected]