title: How to denote an inner singleton in Scala
body: <p>To exercise my OOP abilities on Scala-specific features, I have tried to design a game where I have a <code>Player</code> class. It has an abstract method <code>play</code> which decides, given a list of players (different from the player the method is called on), what action to take. I wanted to prevent the <code>play</code> method to alter the state of this other players. The right way to play is to cast a <code>Spell</code> and let the system reflect its effect on other players. </p>
  
  <p>Yet, the <code>play</code> method needs read access to the other players to decide a strategy. I have thus created an inner singleton <code>ReadOnlyPlayer</code>. I made it a singleton to prevent copying over and over and simply returning this singleton everytime.</p>
  
  <pre><code>abstract class Player(private var _health: Int = 0) {
      Check.isPositive(_health)
  
      def health = _health
  
      def play(players: List[/*?*/]) // how to denote inner type ReadOnlyPlayer ?
  
      def hit(damage: Int) = { _health = max(0, _health - damage); this }
  
      def safeCopy = ReadOnlyPlayer
  
      final object ReadOnlyPlayer extends Player {
          override def health = _health
  
          // noop
          override def hit (damage: Int  ) = this
          override def play(players: List[/*?*/]) = ()
      }
  }
  </code></pre>
  
  <p>I can't get it to compile because of the line I put a comment on. I am aware of a number of workarounds to this issue :</p>
  
  <ul>
  <li><p>if it was a class instead of a singleton, I could use <code>Player#ReadOnlyPlayer</code>. I tried, it works fine. However, this requires to create a new copy everytime, so if I wanted to do this it would actually be better to create a separate immutable class. </p></li>
  <li><p>I could manually implement a singleton pattern and always return the same instance of this class. </p></li>
  <li><p>I could make the class private and only declare <code>Player</code>, but I want my clients to know they explicitly know they won't be able to modify the <code>Player</code> instance. I can do this using an sealed empty trait with a meaningful name.</p></li>
  </ul>
  
  <p>I know how I can handle this in various ways, so my question is more out of curiosity : <strong>how can one denote an inner singleton type ?</strong></p>