title: How is state persisted between function invocations in a functional programming language?
body: <p>I have just started my foray into the functional paradigm from an OO background. I'm confused how state is persisted between function invocations in a functional programming language.</p>
  
  <p>Consider an example of a game that you are creating that you intend to release as a library for others to use.  Others will use your game code as the domain of their game, and hook it up to their own UI.  Using an OO approach, one might expect the client to use your game code like so:</p>
  
  <pre><code>main() {
      Game game = new Game();
  
      while(userHasNotQuit()) {
          // respond to user input
          // call some method that mutates the internal data of the game object
              // ex: game.increaseScore();
          // get the data out of the game object
          // display it on screen
      }
  }
  </code></pre>
  
  <p>Here, the internal data structure of the Game type is hidden from the client and the Game type can expose a public api that defines exactly how the client may interact with the game.  It can achieve data and function hiding because of OO access modifiers.  </p>
  
  <p>I can't seem to figure out how a functional style would work in this situation.  Would the client code need to hold a reference to a data structure and pass that data structure to free functions?  Something like:</p>
  
  <pre><code>main() {
      GameData gameData = createGame(); // structure of data with no methods.
  
      while(userHasNotQuit()) {
          // respond to user input
          // call some function that returns a transformed gameData
              // ex: gameData = increaseScore(gameData);
          // get the data out of the game object
          // display it on screen
      }
  }
  </code></pre>
  
  <p>How would you achieve only exposing certain functions that define your public api, or only exposing certain data from your game data structure?</p>