如何在Scala中使用递归类型T=mutable.Map[Char,T]
我使用递归映射作为如何在Scala中使用递归类型T=mutable.Map[Char,T],scala,Scala,我使用递归映射作为 val collect=mutable.Map[Char,Any]() def next(pos: Int,map: mutable.Map[Char,Any]): Unit = { val ch=a(pos) val d=map.getOrElseUpdate(ch,mutable.Map[Char,Any]()).asInstanceOf[mutable.Map[Char,Any]]
val collect=mutable.Map[Char,Any]()
def next(pos: Int,map: mutable.Map[Char,Any]): Unit = {
val ch=a(pos)
val d=map.getOrElseUpdate(ch,mutable.Map[Char,Any]()).asInstanceOf[mutable.Map[Char,Any]]
for (k <- perehods(pos)) {
next(k,d)
}
}
next(0,collect)
val collect=mutable.Map[Char,Any]()
def next(pos:Int,map:mutable.map[Char,Any]):单位={
val ch=a(位置)
val d=map.getOrElseUpdate(ch,mutable.map[Char,Any]()).asInstanceOf[mutable.map[Char,Any]]
对于(k您不能有递归类型别名,它必须是实际类型:
case class RecMap[A](map: mutable.Map[A, RecMap[A]]) {
def apply(x: A) =
map.getOrElseUpdate(x, RecMap(mutable.Map.empty))
}
def next(pos: Int, rec: RecMap[Char]) = {
val ch=a(pos)
val d=rec(ch)
for (k <- perehods(pos)) {
next(k,d)
}
}
case类RecMap[A](map:mutable.map[A,RecMap[A]]{
def应用(x:A)=
getOrElseUpdate(x,RecMap(mutable.map.empty))
}
def next(位置:Int,记录:记录映射[Char])={
val ch=a(位置)
val d=rec(ch)
对于(k您不能有递归类型别名,它必须是实际类型:
case class RecMap[A](map: mutable.Map[A, RecMap[A]]) {
def apply(x: A) =
map.getOrElseUpdate(x, RecMap(mutable.Map.empty))
}
def next(pos: Int, rec: RecMap[Char]) = {
val ch=a(pos)
val d=rec(ch)
for (k <- perehods(pos)) {
next(k,d)
}
}
case类RecMap[A](map:mutable.map[A,RecMap[A]]{
def应用(x:A)=
getOrElseUpdate(x,RecMap(mutable.map.empty))
}
def next(位置:Int,记录:记录映射[Char])={
val ch=a(位置)
val d=rec(ch)
对于(k