Upload
george-leontiev
View
89
Download
2
Embed Size (px)
Citation preview
About me: @folone likes types*
*same reasons why @propensive does in his “Batshit crazy algebra with types” talk
42.type$ git clone [email protected]:folone/scala.git -b scalaexchange
$ ant publish-local-opt -Dmaven.version.suffix="-typelevel"
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!
Here’s what you cannot
scala> val t: "panda!".type = "panda!"
<console>:1: error: identifier expected
but string literal found.
val t: "panda!".type = "panda!"
^
scala> val x = 42 x: Int = 42
scala> val t: x.type = 42 <console>: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
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
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
QuizLiteral-based singleton types in scala have seen
their first implementation in:
2013 2011 2008 2004
http://existentialtype.net/2008/07/21/literally-dependent-types/
QuizLiteral-based singleton types in scala have seen
their first implementation in:
2013 2011 2008 2004
State of deptypes Scala “Scala vs Idris: Dependent
Types, Now and in the Future”*
*Edwin Brady & Miles Sabin, Strange Loop 2013
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.
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)
val magic: ((x: Int) => x > 23 && x < 42).type = 30
val x: 42 = 42 val x: ((x: Int) => x == 42).type = 42
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
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: