Created
December 10, 2012 12:50
-
-
Save Liutos/4250363 to your computer and use it in GitHub Desktop.
OCaml代码示例
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
(* 定义变量a的值为1 *) | |
let a = 1 | |
(* 定义匿名函数,接收一个整数作为参数,返回结果为其参数的两倍 *) | |
function x -> x*2 | |
(* 定义名为doubel的函数,功能和上面的匿名函数相同 *) | |
let double = function x -> x*2 | |
(* 等价的写法,即语法糖 *) | |
let double x = x*2 |
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
(* 常规的写法 *) | |
1+1 (* 值为2,显而易见 *) | |
(* 函数调用的形式 *) | |
( + ) 1 1 (* 值也为2,这里用了OCaml的currying特性,使得( + )返回一个函数对象 *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment