Skip to content

Latest commit

 

History

History
485 lines (321 loc) · 12.3 KB

presentation-en.md

File metadata and controls

485 lines (321 loc) · 12.3 KB

[fit] 👋

My name is @folone

https://github.com/folone/scalaua


fit


fit



fill inlinefill inlinefill inlinefill inline fill inlinefill inlinefill inlinefill inline


  • 12 hours uploaded every minute
  • ~35k listening years every month
  • 125M tracks (including content from majors: Sony/Universal/Warner)

  • ~170M monthly active users

left

^ quite unique: major labes and dark underground ^ 4x spotify audio (>1PB vs >5PB) ^ 10x smaller team than spotify ^ a lot more interactive, as in the next slide ^ by a huge margin bigger than any competitor in both usage and amount of data (collection size) ^ except for youtube: that's bigger, but they aren't in the audio business per se


^ war stories, we have some fun challenges due to the social nature of soundcloud ^ Drake vs Meek Mill


fill

❤️

fill

^ story about rails app ^ also clojure/jruby


[fit] TLC

👻


[fit] T-L-what now?1

[fit] ಠ_ಠ

^ TLC -- short for typelevel compiler. Name actively endorsed by Daniel Spiewak. ^ A scala fork made by the typelevel organization, to scratch an itch. ^ Typelevel Scala and the future of the Scala ecosystem


[fit] We ❤️ Scala

👻

Roll your own Scala

^ Trying to work around partial type application, infering higher-order types: SI-2712

^ To recap: we’ve taken a few basic (but still pretty broken) Scala language features — singleton types, refinement types, type projections, and the implicit resolution system — and we’ve very painfully built a language for ourselves that at least kind of looks like it supports partial type parameter application, higher-order unification, and multiple implicit parameter sections.


[fit] I think that’s pretty neat,

[fit] but I can also understand why

[fit] almost everyone else would find it

[fit] horrifying.

-- Travis Brown

^ This is not what makes people come to scala ^ but it is what makes some of them stay with it


[fit] TLC

👻

^ For the people who miss pre 2.10 days ^ An incubator for new ideas ^ Beneficial for typesafe scala: they get battle-tested contributions ^ good news: scala will soon be perfect because of The Third System Effect ^ Note: we aren't compiler devs yet, we have full time jobs, and really don't know what we're doing. So don't take anything here as a promise or a final decision or anything that has any level of commitment. The whole point of this talk is to inspire collaboration. ^ Also don't rely on our support for the same set of reasons ^ Backwards compatibility with typesafe scala


[fit] scalaVersion := "2.11.7"

[fit] scalaOrganization := "org.typelevel"

^ sbt is awesome, works starting from 0.13.6 ^ 2.11.8-SNAPSHOT is published as well ^ 2.11.9-SNAPSHOT is published as well


[some] Features

  • Type lambdas
  • @implicitAmbiguous (coming to 2.12 #4673)
  • Singleton types
  • -Zirrefutable-generator-patterns
  • Nifties

left


Type lambdas

trait Functor[F[_]] {
  def map[A, B](fa: F[A])(fn: A => B): F[B]
}

trait LeftFunctor[R] extends
  Functor[({type U[x] = Either[x, R]})#U]

trait RightFunctor[L] extends
  Functor[[y] => Either[L, y]]

Type lambdas

[x] => (x, x)
[x, y] => (x, Int) => y
[x[_]] => x[Double]
[+x, -y] => Function1[y, x]

[fit] Type lambdas

[fit] are cool and all,

[fit] but not a single line

[fit] of the compiler was ever

[fit] written with them in mind

-- Paul Phillips (SI-6895)


@implicitAmbiguous2

// Encoding for "A is not a subtype of B"
trait <:!<[A, B]
 
// Uses ambiguity to rule out the cases we're trying to exclude
implicit def nsub[A, B] : A <:!< B = null
@typelevel.annotation.implicitAmbiguous("Returning ${B} is forbidden.")
implicit def nsubAmbig1[A, B >: A] : A <:!< B = null
implicit def nsubAmbig2[A, B >: A] : A <:!< B = null
 
// Type alias for context bound
type |¬|[T] = {
  type λ[U] = U <:!< T
}
 

@implicitAmbiguous

def foo[T, R : |¬|[Unit]#λ](t: T)(f: T => R) = f(t)
 
foo(23)(_ + 1)   // OK
foo(23)(println) // Doesn't compile: "Returning Unit is forbidden."

Singleton types3

trait Assoc[K] { type V ; val v: V }
 
def mkAssoc[K, V0](k: K, v0: V0): Assoc[k.type] { type V = V0 } =
  new Assoc[k.type] {type V = V0 ; val v = v0}
def lookup[K](k: K)(implicit a: Assoc[k.type]): a.V = a.v

^ Adriaan's implementation


Singleton types

implicit def firstAssoc = mkAssoc(1, "Panda!")
//> firstAssoc : Assoc[Int(1)]{type V = String}
implicit def secondAssoc = mkAssoc(2, 2.0)
//> secondAssoc : Assoc[Int(2)]{type V = Double}

implicit def ageAssoc = mkAssoc("Age", 3)
//> ageAssoc : Assoc[String("Age")]{type V = Int}
implicit def nmAssoc = mkAssoc("Name", "Jane")
//> nmAssoc : Assoc[String("Name")]{type V = String}

Singleton types

lookup(1)
// > res1: String = Panda!
lookup(2)
// > res2: Double = 2.0
lookup("Age")
// > res3: Int = 3
lookup("Name")
// > res4: String = Jane

Irrefutable generator patterns

  for {
    (x, _) <- Option((1, 2))
  } yield x

Desugars to

Some(scala.Tuple2(1, 2))
  .withFilter(((check$ifrefutable$1) =>
    check$ifrefutable$1: @scala.unchecked match {
      case scala.Tuple2((x @ _), _) => true
      case _ => false
    })).map(((x$1) => x$1: @scala.unchecked match {
      case scala.Tuple2((x @ _), _) => x
    }))

With irrefutable patterns

Some(scala.Tuple2(1, 2)).map(((x$1) => x$1 match {
  case scala.Tuple2((x @ _), _) => x
}))

^ This has a few practical differences:

^ Without the flag, non-matching values will be filtered out ^ With the flag, partial patterns will trigger a warning and scala.MatchError could be thrown at runtime (e.g (x, 1) <- Option((1, 2))) ^ Without the flag, you can't have patterns on the left hand side unless the right hand side has withFilter ^ With the flag, desugaring generators in for-comprehension only needs flatMap and map; withFilter is used only for desugaring if.


Няшки

def fib(n: Int) = {
  def fib'(n: Int, next: Int, £: Int): Int =
    n match {
      case 0 => £
      case _ => fib'(n - 1, next + £, next)
    }
  fib'(n, 1, 0)
}

val £': Byte  = 127z

right

^ Mention some nifty things added to the fork


[fit] Vision

💉 🗻

^ no releases of 2.10 ^ will soon drop 2.11, 2.12 only ^ once dotty bootstraps, will switch to it (dotty is the Third System Effect) ^ point is being on the bleeding edge ^ as you can see, we're mostly adding small things and battle-testing them ^ no one one of us is a compiler engineer ^ eventually we plan to get better at compiler development, and work on bigger, more impactful features ^ not to split the community ^ compiler plugin?


[fit] Low-hanging fruits

  • converting partest tests to junit
  • documentation
  • Reporting bugs
  • Fixing bugs
  • Backporting changes from typesafe scala

right


[fit] Let's fantasize a bit now

^ Don't over-promise ^ Note: we aren't compiler devs yet, we have full time jobs, and really don't know what we're doing. So don't take anything here as a promise or a final dicision or anything that has any level of commitement. The whole point of this talk is to inspire collaboration. ^ This is just an exploration of possible ideas, no commitments, etc. ^ Никаких коммитментов, только фантазии


[fit] Refinement types

^ can base them on top of literal-based singleton types ^ going to an external SMT like z3 to prove things about types ^ talked about this last year at scala.exchange ^ generally relying on something external to figure out types would allow us to get the benifits of external research for free as well


[fit] Refinement types

val x: 7.type = 7


[fit] Refinement types

val x: (t => 7).type = 7


[fit] Refinement types

val x: (t => t < 10 && t > 5).type = 7


[fit] Experiment more with stdlib


[fit] Integrating alternative repl

^ Ammonite repl


Rethinking the role of implicits4

left

There's a Prolog in your Scala: http://j.mp/prolog-scala-talk

^ Adriaan's presentation


[fit] Hands-on

scalaVersion      := "2.11.7"
scalaOrganization := "org.typelevel"

^ compiled shapeless and cats with this ^ also works with scala.js ^ who has a project that's 2.11 only?


[fit] What do I do once I check out the repo?

sbt compile sbt test sbt partest

^ Compiling from scratch ~5mins ^ ant билд - legacy ^ sbt publish-local ^ sbt test ~3 minutes ^ sbt partest ~1 hour


./tools/partest-ack


[fit] To summarize

^ Beneficial for typesafe and typelevel ^ No community splitting ^ Bleeding edge ^ Try now, contribute ^ We'll be reviving the project, marking low-hanging fruit tasks, etc.


[fit] Danke!

@folone

https://soundcloud.com/jobs

Footnotes

  1. http://typelevel.org/blog/2014/09/02/typelevel-scala.html

  2. https://gist.github.com/milessabin/c9f8befa932d98dcc7a4

  3. requeires -Xexperimental flag

  4. https://github.com/typelevel/scala/issues/28 -- @implicitWeight