我怎麼能在斯卡拉字符串模式匹配:模式匹配的字符串在斯卡拉
scala> "55" match {
| case x :: _ => x
| }
<console>:9: error: constructor cannot be instantiated to expected type;
found : scala.collection.immutable.::[B]
required: String
case x :: _ => x
^
在Haskell一個String
是char [Char]
的列表:
Prelude> :i String
type String = [Char] -- Defined in `GHC.Base'
所以它支持模式匹配在String
。
我該如何在Scala中做到這一點?
我要補充一個答案,但重複的問題涵蓋了很好 – 2014-09-20 15:25:18
謝謝你指出這件事。我的錯誤(但我很高興從extempore的回答中學到) – 2014-09-20 15:27:11