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

ScalaWorld 2015 Recap

ScalaWorld 2015 Recap

Some highlights of ScalaWorld 2015 conference (https://scala.world) that was held on September 20-22 in Lake District, UK.

Dmitry Ivanov

October 01, 2015
Tweet

More Decks by Dmitry Ivanov

Other Decks in Programming

Transcript

  1. ScalaWorld 2015
    Recap
    Joost Heijkoop
    Dmitry Ivanov (@idajantis)
    Amsterdam.Scala meetup
    1st October 2015

    View full-size slide

  2. 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-

    View full-size slide

  3. 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 }

    View full-size slide

  4. Use Cases
    • Real-world internet protocols (e.g. POP3 example, SMTP)
    • Multi-party concurrency problems (e.g. dining philosophers)
    https://github.com/epsrc-abcd/session-types-use-cases

    View full-size slide

  5. Beyond Scala Lens
    by Julien Truffaut @julientruffaut
    Slides http://www.slideshare.net/JulienTruffaut/beyond-scala-lens

    View full-size slide

  6. 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

    View full-size slide

  7. 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

    View full-size slide

  8. Automatic case class binding (via Shapeless HLists)
    case class Point(x: Int, y: Int, z: Int)
    val pointCodec = (int8 :: int8 :: int8).as[Point]
    val encoded: Attempt[BitVector] = pointCodec.encode(Point(-5, 10, 1))
    // Successful(BitVector(24 bits, 0xfb0a01))
    val decoded: Attempt[DecodeResult[Point]] = pointCodec.decode(hex"0xfb0a01".bits)
    // Successful(DecodeResult(Point(-5,10,1),BitVector(empty)))

    View full-size slide

  9. Example: Discrimitator fields support in DSL
    (int32 :+: bool(8) :+: variableSizeBytes(uint8, ascii))
    .discriminatedByIndex(uint8)

    View full-size slide

  10. Need for Async
    by Konrad Malawski @ktosopl
    • Tail latency: measure the right thing
    • Always bench, don't assume
    • Check the SLA for all percentiles

    View full-size slide

  11. Need for Async
    • Lock-free and Wait-free algorithms:
    "concurrent < lock-free < wait-free"
    • "Functional outside, Intel inside: Sorting"
    • JMH sbt plugin in action: perf_events, perf_asm integration
    • Flame graphs
    • Slides: http://www.slideshare.net/ktoso/the-need-for-async-
    scalaworld

    View full-size slide

  12. 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#/

    View full-size slide

  13. * Lift Literal Values to Types
    scala> val x: 3 = 1 + 2
    x: 3 = 3
    SIP-23: http://docs.scala-lang.org/sips/pending/42.type.html.
    Still WIP.

    View full-size slide

  14. * 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

    View full-size slide

  15. * 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

    View full-size slide

  16. * 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 { .... }]

    View full-size slide

  17. Type-driven Development in Idris
    by Edwin Brady @edwinbrady
    • Idris (http://www.idris-lang.org)
    A Language with Dependent Types.
    • Dependent Types
    Value-level constructions ~= Type-level constructions
    • Haskell-like syntax
    • Code generators: Java, JavaScript, PHP (o_O), C(?), ...

    View full-size slide

  18. Idris Dependent Types
    app : Vect n a -> Vect m a -> Vect (n + m) a
    app Nil ys = ys
    app (x :: xs) ys = x :: app xs ys

    View full-size slide

  19. Heuristics for approachable,
    modular and functional libraries
    by Erik Osheim @d6
    Slides: http://plastic-idolatry.com/erik/sw2015.pdf

    View full-size slide

  20. 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"

    View full-size slide

  21. 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.

    View full-size slide

  22. Modular
    Strive for modularity.
    Move small & useful utilities to standalone projects.
    Use & support other libraries.
    Platform independent by default. Case: cats.JVM / cats.JS.

    View full-size slide

  23. 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

    View full-size slide

  24. 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.

    View full-size slide

  25. 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)

    View full-size slide

  26. Questions? :)

    View full-size slide

  27. Naming things and finding cothings
    .

    View full-size slide