Created
January 16, 2014 19:33
-
-
Save mfbx9da4/8461760 to your computer and use it in GitHub Desktop.
Same contrived functional program but in go
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
package main | |
import fmt "fmt" | |
type IntFunc func(int) int | |
type HiIntFunc func(int) IntFunc | |
func first(a int) HiIntFunc { | |
return func(b int) IntFunc { | |
return func(c int) int { | |
if c < 4 { | |
return c * (b + a) | |
} else { | |
return first(a)(b)(c-1) | |
} | |
return 0 | |
} | |
} | |
} | |
func main(){ | |
var n int = 4 | |
var answer int = 0 | |
var second HiIntFunc = first(n) | |
var third IntFunc = second(n * 2) | |
answer = third(n * 3) | |
fmt.Printf("%d\n", answer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment