Strange Scala error.

Posted by Lukasz Lew on Stack Overflow See other posts from Stack Overflow or by Lukasz Lew
Published on 2010-06-13T17:23:23Z Indexed on 2010/06/13 18:32 UTC
Read the original article Hit count: 338

Filed under:
|

I tried to create abstract turn based Game and abstract AI:

abstract class AGame {
  type Player
  type Move     // Player inside

  def actPlayer : Player
  def moves (player : Player) : Iterator[Move]
  def play (move : Move)
  def undo ()
  def isFinished : Boolean
  def result (player : Player) : Double
}

abstract class Ai[Game <: AGame] {
  def genMove (player : Game#Player) : Game#Move
}

class DummyGame extends AGame {
  type Player = Unit
  type Move = Unit

  def moves (player : Player) = new Iterator[Move] {
    def hasNext = false
    def next = throw new Exception ("asd")
  }

  def actPlayer = ()

  def play (move : Move) {
  }

  def undo () {
  }

  def isFinished = true

  def result (player : Player) = 0
}

class DummyAi[Game <: AGame] (game : Game) extends Ai[Game] {
  override def genMove (player : Game#Player) : Game#Move = {
    game.moves (player).next
  }
}

I thought that I have to use this strange type accessors like Game#Player. I get very puzzling error. I would like to understand it:

[error] /home/lew/Devel/CGSearch/src/main/scala/Main.scala:41: type mismatch;
[error]  found   : Game#Player
[error]  required: DummyAi.this.game.Player
[error]     game.moves (player).next
[error]                 ^

© Stack Overflow or respective owner

Related posts about scala

Related posts about types