Skip to content

Instantly share code, notes, and snippets.

@Liutos
Created December 10, 2012 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Liutos/4250363 to your computer and use it in GitHub Desktop.
Save Liutos/4250363 to your computer and use it in GitHub Desktop.
OCaml代码示例
(* 定义变量a的值为1 *)
let a = 1
(* 定义匿名函数,接收一个整数作为参数,返回结果为其参数的两倍 *)
function x -> x*2
(* 定义名为doubel的函数,功能和上面的匿名函数相同 *)
let double = function x -> x*2
(* 等价的写法,即语法糖 *)
let double x = x*2
(* 常规的写法 *)
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