Skip to content

Instantly share code, notes, and snippets.

@st98
Last active August 29, 2015 14:13
Show Gist options
  • Save st98/8f331d3a5c0bfd08ff21 to your computer and use it in GitHub Desktop.
Save st98/8f331d3a5c0bfd08ff21 to your computer and use it in GitHub Desktop.
OCaml 入門。http://try.ocamlpro.com/ の Lesson 4 辺り。
(* 試す *)
let f = function
| [| x; (_, _) |] -> x
| _ -> 0, 0;;
f [| 1, 2; 3, 4 |];; (* => (1, 2) *)
let f = function
| [| x; _ |]::_ -> x
| _ -> 0, 0;;
f [[| 1, 2; 3, 4 |]];; (* => (1, 2) *)
(* http://try.ocamlpro.com/ の Lesson 4 Step 5 の下 *)
let f = function
| [] -> failwith "empty list"
| [| _; (_, x) |]::_ -> x
| _ -> failwith "the first array should be of size two"
f [[| 1, 2; 3, 4 |]];; (* => 4 *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment