From f9d504466731c5be1dae3303e57ea0f975a117cf Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Fri, 11 Dec 2020 13:40:29 -0800 Subject: [PATCH] FAQ: include short answers before linking to longer texts --- _overviews/FAQ/index.md | 52 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/_overviews/FAQ/index.md b/_overviews/FAQ/index.md index 660ad6e25c..e187410b13 100644 --- a/_overviews/FAQ/index.md +++ b/_overviews/FAQ/index.md @@ -79,7 +79,7 @@ official documentation that addresses it, not just an FAQ answer --> see the [Scala 2.13 Collections Guide](https://docs.scala-lang.org/overviews/collections-2.13/introduction.html) -### What are Scala context bounds (`[T : Foo]`)? +### What are context bounds (`[T : Foo]`)? [answer on Stack Overflow](https://stackoverflow.com/a/4467012) @@ -110,28 +110,56 @@ One would hope so, but doing it that way was tried and it proved impossible. [This SO question](https://stackoverflow.com/questions/11167430/why-are-primitive-types-such-as-int-erased-to-object-in-scala) sadly lacks a concise explanation, but it does link to past discussions. -### Difference between methods and functions +### What's the difference between methods and functions? + +For example, how does a method such as: + + def square(x: Int): Int = x * x + +differ from a function value such as: + + val square: Int => Int = x => x * x [complete answer on Stack Overflow](https://stackoverflow.com/a/2530007/4111404) [summary with practical differences](https://tpolecat.github.io/2014/06/09/methods-functions.html) -### Difference between classes and types +### What's the difference between types and classes? + +Types are primarily a compile-time concept. At compile time, +every expression is assigned a type by the compiler. + +Classes are primarily a runtime concept and are platform-dependent. +At runtime on the JVM, every value is either a primitive value +or an instance of exactly one class. + +Some type information exists only at compile time, for multiple +reasons, most notoriously [type +erasure](https://en.wikipedia.org/wiki/Type_erasure). + +For an in-depth treatment of types vs. classes, see the blog post +["There are more types than classes"](https://typelevel.org/blog/2017/02/13/more-types-than-classes.html). + +### How can a method in a superclass return a value of the “current” type? -[blog post: There are more types than classes](https://typelevel.org/blog/2017/02/13/more-types-than-classes.html) +Possible solutions include F-bounded polymorphism (familiar to Java programmers), +type members, and the typeclass pattern. -### How to return "current" type +[discussion of alternatives on Stack Overflow](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob) -[discussion about alternatives and their trade-offs on Stack Overflow](https://stackoverflow.com/questions/59813323/advantages-of-f-bounded-polymorphism-over-typeclass-for-return-current-type-prob) +[blog post](http://tpolecat.github.io/2015/04/29/f-bounds.html) arguing against F-bounds and in favor of typeclasses. -### What does <:< means? +### What does `<:<` mean? -[blog post: Generalized type constraints](https://blog.bruchez.name/2015/11/generalized-type-constraints-in-scala.html) +It's a "type constraint", and it comes from the standard library, +not from the language itself. See [this blog +post](https://blog.bruchez.name/2015/11/generalized-type-constraints-in-scala.html). -### Best way to model optional arguments +### I dislike requiring callers to wrap optional arguments in `Some(...)`; is there a better way? -[answer on Stack Overflow](https://stackoverflow.com/a/65256691/4111404) +Not really. See [this answer on Stack Overflow](https://stackoverflow.com/a/65256691/4111404). -### Why prfer implicit val over implicit object +### Why is `implicit val` usually recommended over `implicit object`? -[answer on Stack Overflow](https://stackoverflow.com/a/65258340/4111404) +The latter has a singleton type, which is too specific. See [answer on Stack +Overflow](https://stackoverflow.com/a/65258340/4111404).