我怎么能在斯卡拉字符串模式匹配:模式匹配的字符串在斯卡拉
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