Created
September 25, 2014 10:57
-
-
Save akanehara/ca22e8d9950d11f3b5b8 to your computer and use it in GitHub Desktop.
受け取ったリストの長さを返す関数length
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
(* 目的: 受け取ったリストの長さを返す関数length *) | |
(* length : 'a list -> int *) | |
let rec length xs = | |
match xs with | |
[] -> 0 | |
| first :: rest -> 1 + length rest;; | |
(* テスト *) | |
let length1 = length [] = 0;; | |
let length2 = length [1] = 1;; | |
let length3 = length [1;2] = 2;; | |
let length4 = length [1;2;3] = 3;; | |
let length5 = length ["a"] = 1;; | |
let length6 = length ["a";"b"] = 2;; | |
let length7 = length ["a";"b";"c"] = 3;; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment