title: Recursive Enumerations in Swift
body: <p>I'm learning Swift 2 (and C, but also not for long) for not too long and I came to a point where I struggle a lot with recursive enumerations.</p>
  
  <p>It seems that I need to put <code>indirect</code> before the <code>enum</code> if it is recursive. Then I have the first case which has <code>Int</code> between the parentheses because later in the switch it returns an <code>Integer</code>, is that right?</p>
  
  <p>Now comes the first problem with the second case <code>Addition</code>. There I have to put <code>ArithmeticExpression</code> between the parentheses. I tried putting <code>Int</code> there but it gave me an error that is has to be an <code>ArithmeticExpression</code> instead of an <code>Int</code>. My question is why? I can't imagine anything what that is about. Why can't I just put two <code>Int</code>s there?</p>
  
  <p>The next problem is about <code>ArithmeticExpression</code> again. In the <code>func</code> <code>solution</code> it goes in an value called expression which is of the type <code>ArithmeticExpression</code>, is that correct? The rest is, at least for now, completely clear. If anyone could explain that to me in an easy way, that'd be great.</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>indirect enum ArithmeticExpression {
      case Number(Int)
      case Addition(ArithmeticExpression, ArithmeticExpression)
  }
  
  func solution(expression: ArithmeticExpression) -&gt; Int {
      switch expression {
      case .Number(let value1):
          return value1;
      case . Addition(let value1, let value2):
          return solution(value1)+solution(value2);
      }
  }
  
  var ten = ArithmeticExpression.Number(10);
  var twenty = ArithmeticExpression.Number(20);
  var sum = ArithmeticExpression.Addition(ten, twenty);
  var endSolution = solution(sum);
  print(endSolution);
  </code></pre>