• MinCaml (※) ͷ࣮ϕʔε • https://github.com/rhysd/gocaml ˞IUUQTHJUIVCDPNFTVNJJNJODBNM let rec gcd m n = if m = 0 then n else if m <= n then gcd m (n - m) else gcd n (m - n) in print_int (gcd 21600 337500)
*) let r = 9.0 in let pi = 3.14 in let area = r *. r *. pi in print_float area; (* ࠶ఆٛʢshadowingʣ OK *) let r = 4 in let area = r * r in print_int area /* Go */ func main() { r := 9.0 pi := 3.14 area := r * r * pi fmt.Print(area) { r := 4 area := r * r fmt.Print(area) } }
rec squre x = x *. x in squre 3.0; (* Ϋϩʔδϟ *) let PI = 3.14 in let rec f d = PI *. d *. d in (* ؔͱͯ͑͠Δ *) let rec compose f g = let rec h x = f (g x) in h in let f = compose squre squre in /* Go */ func squre(x float64) float64 { return x * x } func main() { squre(3.0) PI := 3.14 circle := func(d float64) float64 { return PI * d * d } type F func(f float64) float64 compose := func(f F, g F) F { return func(x float64) float64 { return g(f(x)) } } f := compose(squre, squre) }
• x : int ͔ bool ͔ float • y : int ͔ bool ͔ float // Go ٖࣅίʔυ func lessFirst(a, b) { x := a[0] y := b[0] return x < y } func main() { p := []int{1} lessFirst(p, p) }
• x : int ͔ bool ͔ float • y : int ͔ bool ͔ float • main : () -> ? • p : (int array) // Go ٖࣅίʔυ func lessFirst(a, b) { x := a[0] y := b[0] return x < y } func main() { p := []int{1} lessFirst(p, p) }
• x : int ͔ bool ͔ float • y : int ͔ bool ͔ float • main : () -> () • p : (int array) // Go ٖࣅίʔυ func lessFirst(a, b) { x := a[0] y := b[0] return x < y } func main() { p := []int{1} lessFirst(p, p) }
{ PI := 3.14 func circle(x float64) float64 { return x * x * PI } circle(3.0) } // ! ΫϩʔδϟͩͱͲ͏ͳΔʁ // PI ΛͲ͏ʹ͔ୡ͢Δඞཁ͕͋Δ func circle(x float64) float64 { return x * x * PI } func main() { PI := 3.14 circle(3.0) }
{ PI := 3.14 func circle(x float64) float64 { return x * x * PI } circle(3.0) } // ! ؔʹΩϟϓνϟ͞ΕΔΛӅΕҾͱͯ͢͠ඞཁ͕͋Δ type Captures struct { PI float64 } func circle(cap Captures, x float64) float64 { PI := cap.PI return x * x * PI } func main() { PI := 3.14 circle(Captures{PI}, 3.0) }