The Newest in Session Types by Roland Kuhn @rolandkuhn From Data Types to Session Types Session - a unit of conversation. Session Type - the structure of a conversation, a sequence of interactions in a communication-centric program model. Primitives: sending, receiving, sequence, choice, recursion Scribble language. Slides: http://www.slideshare.net/rolandkuhn/the-newest-in-
An Example • global protocol (a asks b to calculate "x / y"): a -> b: . a -> b: . b -> a: { ok: b -> a: . end, fail: end } • local projection for a: [b]!. [b]!. [b]? { ok: [b]?. end, fail: end } • local projection for b: [a]?. [a]?. [a]! { ok: [a]!. end, fail: end }
Optics overview Nice explanation of how Iso, Prism, Lens work. • Iso f: S => A, g: A => S • Prism f: S => Option[A], g: A => S • Lens f: S => A, g: (A, S) => S Introduced a new Optic type: Optional • Optional f: S => Option[A], g: (A, S) => S
Practical Binary with Scodec by Michael Pilquist @mpilquist Scodec - a Shapeless-powered library for working with binary protocols. Codec = serializer + deserializer Via Shapeless: automatic codec derivation, cached implicit instances, etc. Slides: https://speakerdeck.com/mpilquist/practical-binary- with-scodec-and-shapeless
Implicits 2.0 / Levelling UP Scala by Adriaan Moors @adriaanm • Lift Literal Values to Types • Opaque Type Members • Implicit Types • Matching on Types Slides: http://adriaanm.github.io/reveal.js/levelup.html#/
* Opaque Type Members Bringing val and type a bit closer class C { type T <: Int = 1 ; def foo(x: T) } class D { override type T <: Int = 2 } extends C Before: type alias is implicitly final
* Implicit Types "let's not identify types from witnesses" class C { implicit type T <: Int = 1 } Then: def foo(x: C)(implicit w: x.T) = println(w) foo(new C) // prints 1 foo(new D) // prints 2
* Matching on Types class Set[T] { type BuilderFor[U] <: SetBuilder[U] = DefaultSetBuilder[U] } class BitSet extends Set[Int] { type BuilderFor[U] <: SetBuilder[U] = U match { case Int => BitSetBuilder case t => super.BuilderFor[t] } } What is valueOf[T match { .... }]
Things learned from Spire • Always benchmark new features • Property-based testing FTW: scalacheck, scalaprops • "If you care about testing, measure code coverage" • Mistake: making a monolithic project • Enforce consistency: scalastyle (http://www.scalastyle.org) • Type Classes shouldn't have default implementation. "Avoid inefficient default implementations"
Use Eval[T] for laziness Three branches: eager val, lazy val and def Advantage of Eval[T]: you can return a lazy value. By-name params: no memoization, type system doesn't distinguish A and (=> A), (=> A) unconditionally allocates a Function0[A] Abstracting over laziness and eagerness using Type Constructors.
Modular Strive for modularity. Move small & useful utilities to standalone projects. Use & support other libraries. Platform independent by default. Case: cats.JVM / cats.JS.
Constraints Liberate, Liberties Constrain by Rúnar Bjarnason @runarorama Type constraints: Actors vs Futures for concurrency Premature: Loss of precision, Concretisation, Folding, Compilation, Optimisation. • Reach for the least powerful abstraction • Detonate as late as possible • Premature loss of precision is the root of all evil
Other Notes Awesome conf report from Guardian: https://www.theguardian.com/info/developer-blog/live/2015/ sep/21/conference-report-scala-world-2015 My talks TODO list: • "A Deep Dive into Scalac...", Chris Birchal. • "Typelevel Programming 101", Joe Barnes. • "Reactive Streams / Akka Stream", Mathias Doenitz & Johannes Rudolph.
SIP-2712 SIP-2712: "Implement higher-order unification for type constructor inference"* object Test { def meh[M[_], A](x: M[A]): M[A] = x meh{(x: Int) => x} // should solve ?M = [X] X => X and ?A = Int ... } console>:9: error: no type parameters for method meh: (x: M[A])M[A] exist so that it can be applied to arguments (Int => Int) Workaround from Miles Sabin: continuation passing style on a type level! (check "Kittens - Shapeless Typeclass Derivation for Cats" talk)