PageRenderTime 43ms CodeModel.GetById 41ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/scala/scalagym/Curry.scala

http://github.com/mariofusco/scalagym
Scala | 30 lines | 6 code | 7 blank | 17 comment | 2 complexity | e99e1c1b7823a2f864cef7d2d61a2b4a MD5 | raw file
 1package scalagym
 2
 3/**
 4 * @author Mario Fusco
 5 */
 6
 7object Curry extends Application {
 8/*
 9  def sum(f: Int => Int): (Int, Int) => Int = {
10    def sumF(a: Int, b: Int): Int =
11      if (a > b) 0 else f(a) + sumF(a + 1, b)
12    sumF
13  }
14
15  val sum1To10 = sum(x => x)(1, 10)
16*/
17
18
19  def sum(f: Int => Int)(a: Int, b: Int): Int = if (a > b) 0 else f(a) + sum(f)(a + 1, b)
20
21  val sum1To10 = sum(x => x)(1, 10)
22
23
24/*
25  def sum(a: Int, b: Int)(f: Int => Int): Int = if (a > b) 0 else f(a) + sum(a + 1, b)(f)
26
27  val sum1To10 = sum(1, 10) { x => x }
28*/
29  println(sum1To10)
30}