title: How to Translate Dictionary of Functions
body: <p>I struggled to think of a good title here, but hopefully my description makes up for it.</p>
  
  <p>As a hobby side-project, I'm attempting to port an interpreter for a <a href="https://interpreterbook.com/" rel="nofollow noreferrer">toy language</a> (you have to pay for the book, just linking to show where I am coming from) from Go to F#.</p>
  
  <p>This has all gone fine until the point where I am needing to call other functions in a dictionary of functions.</p>
  
  <p>Here's a very simplified example of what the Go code tries to do written in F#:</p>
  
  <pre><code>let processA a remainingCharacters =
      1
  
  let processB b remainingCharacters =
      2
  
  let processC c remainingCharacters =
      // this doesn't work, obviously, as funcMap is declared below
      let problem = funcMap.[remainingCharacters.Head]
      3 + problem
  
  // i assume there is a better way of doing this, I'm just not sure what it is
  let funcMap = dict[('a', processA); ('b', processB); ('c', processC)]
  
  let processCharacter currentCharacter remainingCharacters =
      let processFunc = funcMap.[currentCharacter]
      processFunc currentCharacter remainingCharacters
  
  let input = ['a'; 'b'; 'a'; 'c']
  let processInput() =
      let rec processInputRec currentCharacter (remainingCharacters: char list) sum =
          if remainingCharacters.IsEmpty then
              sum
          else
              let currentValue = processCharacter currentCharacter remainingCharacters
              processInputRec remainingCharacters.Head remainingCharacters.Tail (sum + currentValue)
      processInputRec input.Head input.Tail 0
  
  let result = processInput()
  sprintf "%i" result |&gt; ignore
  </code></pre>
  
  <p>So basically, it is trying to map given input values to different functions and in certain cases, needing to refer back to that mapping (or at least getting at another one of those mapped functions) inside those functions.</p>
  
  <p>How would I go about doing that in F#?</p>