-
-
Save st98/8f331d3a5c0bfd08ff21 to your computer and use it in GitHub Desktop.
OCaml 入門。http://try.ocamlpro.com/ の Lesson 4 辺り。
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
(* 試す *) | |
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