Created
July 8, 2012 04:02
-
-
Save imeredith/3069244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum(f: Int => Int)(a: Int, b: Int): Int = { | |
if (a > b) 0 else f(a) + sum(f)(a + 1, b) | |
} | |
def sumInts = sum(x => x) _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum(f: Int => Int): (Int, Int) => Int = { | |
def sumF(a: Int, b: Int): Int = | |
if (a > b) 0 else f(a) + sumF(a + 1, b) | |
sumF | |
} | |
def sumInts = sum(x => x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def sum(f: Int => Int)(a: Int, b: Int): Int = {
if (a > b) 0 else f(a) + sum(f)(a + 1, b)
}
def sumInts = sum(x => x) _