summaryrefslogblamecommitdiff
path: root/test/pos/cours2a.scala
blob: b888b88a9600d5e373ac6301597a47f943320e1f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16















                                           
module m1 {
  def factorial(n: Int): Int =
    if (n == 0) 1
    else n * factorial(n-1);
}

module m2 {

  def factorial(n: Int): Int = {
    def factIter(n: Int, acc: Int): Int = {
      if (n == 0) acc
      else factIter(n - 1, acc * n)
    }
    factIter(n, 1)
  }
}