Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Created January 16, 2014 19:33
Show Gist options
  • Save mfbx9da4/8461760 to your computer and use it in GitHub Desktop.
Save mfbx9da4/8461760 to your computer and use it in GitHub Desktop.
Same contrived functional program but in go
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