scala-2.8

What are Scala continuations and why use them?

本小妞迷上赌 提交于 2019-11-26 12:49:53
问题 I just finished Programming in Scala , and I\'ve been looking into the changes between Scala 2.7 and 2.8. The one that seems to be the most important is the continuations plugin, but I don\'t understand what it\'s useful for or how it works. I\'ve seen that it\'s good for asynchronous I/O, but I haven\'t been able to find out why. Some of the more popular resources on the subject are these: Delimited continuations and Scala Goto in Scala A Taste of 2.8: Continuations Delimited Continuations

Scala pattern matching with lowercase variable name

馋奶兔 提交于 2019-11-26 12:45:19
问题 I found that when using pattern matching with alternatives (for strings), Scala accepts variables starting with upper case (in the example below, MyValue1 and MyValue2 ), but not those starting with lower case ( myValue1 , myValue2 ). Is this a bug or a feature of Scala? I get this in version 2.8. If this is a feature, can anyone explain the rationale behind it? This is the code I used: val myValue1 = \"hello\" val myValue2 = \"world\" val MyValue1 = \"hello\" val MyValue2 = \"world\" var x

Overload constructor for Scala's Case Classes?

依然范特西╮ 提交于 2019-11-26 12:12:48
问题 In Scala 2.8 is there a way to overload constructors of a case class? If yes, please put a snippet to explain, if not, please explain why? 回答1: Overloading constructors isn't special for case classes: case class Foo(bar: Int, baz: Int) { def this(bar: Int) = this(bar, 0) } new Foo(1, 2) new Foo(1) However, you may like to also overload the apply method in the companion object, which is called when you omit new . object Foo { def apply(bar: Int) = new Foo(bar) } Foo(1, 2) Foo(1) In Scala 2.8,

Scala 2.8 CanBuildFrom

萝らか妹 提交于 2019-11-26 10:29:41
问题 Following on from another question I asked, Scala 2.8 breakout , I wanted to understand a bit more about the Scala method TraversableLike[A].map whose signature is as follows: def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That Notice a few things about this method: It takes a function turning each A in the traversable into a B . It returns That and takes an implicit argument of type CanBuildFrom[Repr, B, That] . I can call this as follows: > val s: Set[Int] = List(\

Implementing yield (yield return) using Scala continuations

那年仲夏 提交于 2019-11-26 10:22:55
问题 How might one implement C# yield return using Scala continuations? I\'d like to be able to write Scala Iterator s in the same style. A stab is in the comments on this Scala news post, but it doesn\'t work (tried using the Scala 2.8.0 beta). Answers in a related question suggest this is possible, but although I\'ve been playing with delimited continuations for a while, I can\'t seem to exactly wrap my head around how to do this. 回答1: Before we introduce continuations we need to build some

Scala 2.8 collections design tutorial

夙愿已清 提交于 2019-11-26 10:04:36
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. Following on from my breathless confusion, what are some good resources which explain how the new Scala 2.8 collections library has been structured. I\'m interested to find some information on how the following fit together: The collection classes/traits themselves (e.g. List , Iterable ) Why the Like classes exist (e.g

How to write to a file in Scala?

醉酒当歌 提交于 2019-11-26 00:46:47
问题 For reading, there is the useful abstraction Source . How can I write lines to a text file? 回答1: Edit 2019 (8 years later), Scala-IO being not very active, if any, Li Haoyi suggests his own library lihaoyi/os-lib, that he presents below. June 2019, Xavier Guihot mentions in his answer the library Using, a utility for performing automatic resource management. Edit (September 2011): since Eduardo Costa asks about Scala2.9, and since Rick-777 comments that scalax.IO commit history is pretty much

What is a “context bound” in Scala?

给你一囗甜甜゛ 提交于 2019-11-26 00:17:37
问题 One of the new features of Scala 2.8 are context bounds. What is a context bound and where is it useful? Of course I searched first (and found for example this) but I couldn\'t find any really clear and detailed information. 回答1: Did you find this article? It covers the new context bound feature, within the context of array improvements. Generally, a type parameter with a context bound is of the form [T: Bound] ; it is expanded to plain type parameter T together with an implicit parameter of

What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

戏子无情 提交于 2019-11-25 23:36:08
问题 I can see in the API docs for Predef that they\'re subclasses of a generic function type (From) => To, but that\'s all it says. Um, what? Maybe there\'s documentation somewhere, but search engines don\'t handle \"names\" like \"<:<\" very well, so I haven\'t been able to find it. Follow-up question: when should I use these funky symbols/classes, and why? 回答1: These are called generalized type constraints . They allow you, from within a type-parameterized class or trait, to further constrain

Scala 2.8 breakOut

白昼怎懂夜的黑 提交于 2019-11-25 22:32:33
问题 In Scala 2.8 , there is an object in scala.collection.package.scala : def breakOut[From, T, To](implicit b : CanBuildFrom[Nothing, T, To]) = new CanBuildFrom[From, T, To] { def apply(from: From) = b.apply() ; def apply() = b.apply() } I have been told that this results in: > import scala.collection.breakOut > val map : Map[Int,String] = List(\"London\", \"Paris\").map(x => (x.length, x))(breakOut) map: Map[Int,String] = Map(6 -> London, 5 -> Paris) What is going on here? Why is breakOut being