The code is coming from https://gist.github.com/jrudolph/66925:
object TowersOfHanoi {
import scala.reflect.Manifest
def simpleName(m:Manifest[_]):String = {
val name = m.toString
name.substring(name.lastIndexOf('$')+1)
}
trait Nat
final class _0 extends Nat
final class Succ[Pre<:Nat] extends Nat
type _1 = Succ[_0]
type _2 = Succ[_1]
type _3 = Succ[_2]
type _4 = Succ[_3]
case class Move[N<:Nat,A,B,C]()
implicit def move0[A,B,C](implicit a:Manifest[A],b:Manifest[B]):Move[_0,A,B,C] = {
System.out.println("Move from "+simpleName(a)+" to "+simpleName(b));null
}
implicit def moveN[P<:Nat,A,B,C](implicit m1:Move[P,A,C,B],m2:Move[_0,A,B,C],m3:Move[P,C,B,A])
:Move[Succ[P],A,B,C] = null
def run[N<:Nat,A,B,C](implicit m:Move[N,A,B,C]) = null
case class Left()
case class Center()
case class Right()
def main(args:Array[String]){
run[_2,Left,Right,Center]
}
}
I remember when I compiled it, it outputed something like "Move from Left to Right" several years ago with Scala 2.8
.
Today, I tried it with Scala 2.11.4
, it doesn't output anything!
Is there any changes to Scala? And how to fix it?
WFM (works for me)
scala> TowersOfHanoi.main(null)
Move from Left to Right
Move from Left to Center
Move from Right to Center
Move from Left to Right
Move from Center to Left
Move from Center to Right
Move from Left to Right
I will profess not to grok the code itself - the implicits/types are obtuse and in old Manifest style. 2.10+ prefers TypeTags / ClassTags.