behavior in Java that is difficult to predict or explain • This presentation: ◦ Weird behavior in Scala that confounds beginners ▪ (and sometimes experienced programmers) ◦ FAQs, not Fun
to create and turn Scala into what it is. Furthermore, if you learn anything from this presentation, learn that a perfect understanding of Scala is an unlikely achievement... Disclaimer #2: don't trust me.
external libraries; it can be difficult to tell where they begin and end; they are difficult to search for on the Internet, non-mnemonic and unpronounceable.
α, β]})#λ] = { new Category[({type λ[α, β] = Kleisli[M, α, β]})#λ] { def id[A] = ☆(_ η) def compose[X, Y, Z](f: Kleisli[M, Y, Z], g: Kleisli[M, X, Y]) = f <=< g } } Let's try to figure this one out
α, β]})#λ] = { new Category[({type λ[α, β] = Kleisli[M, α, β]})#λ] { def id[A] = ☆(_ η) def compose[X, Y, Z](f: Kleisli[M, Y, Z], g: Kleisli[M, X, Y]) = f <=< g } } Identify what we are defining
α, β]})#λ] = { new Category[({type λ[α, β] = Kleisli[M, α, β]})#λ] { def id[A] = ☆(_ η) def compose[X, Y, Z](f: Kleisli[M, Y, Z], g: Kleisli[M, X, Y]) = f <=< g } } Where we are using our definitions
an eta expansion: turn method f into an anonymous function. • f(_, y) ◦ a partial function application: creates an anonymous function from method f, whose parameters are the ones wholly replaced by underscores. • f(x + _, y) ◦ a placeholder: creates an anonymous function from the expression "x + _", whose parameters are the underscores (and that function gets passed to f).
Scala added metadata to "eliminate" erasure, the interaction gap between it and Java would be much greater ◦ Though things like implicits and default parameters already do it, to some extent ◦ At least, implicits and defaults are easy to avoid
= 10 println("In A: foo: " + foo + ", bar: " + bar) } class B extends A { val foo: Int = 25 println("In B: foo: " + foo + ", bar: " + bar) } class C extends B { override val bar = 99 println("In C: foo: " + foo + ", bar: " + bar) } new C Source: Paul Phillips scala-faq by way of scala puzzlers
= 10 println("In A: foo: " + foo + ", bar: " + bar) } class B extends A { val foo: Int = 25 println("In B: foo: " + foo + ", bar: " + bar) } class C extends B { override val bar = 99 println("In C: foo: " + foo + ", bar: " + bar) } new C
trait B { val x: Int println(x * 2) } trait C extends A with B trait D extends B class E extends D with C { println(x * 2) } class F extends C with D { println(x * 2) } new E new F
trait B { val x: Int println(x * 2) } trait C extends A with B trait D extends B class E extends B with D with A with B with C { println(x * 2) } class F extends A with B with C with B with D { println(x * 2) } new E new F
there's a wide range of Scala features that depend on the user having deep knowledge of the language when something goes wrong. "What's going on?" seems to be much more common than "How do I do this?"