Last active
August 29, 2015 14:06
-
-
Save akanehara/7ae0a22ffbb0da72f438 to your computer and use it in GitHub Desktop.
血液型がAの人物の数を返す関数 count_ketsueki_A
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
(* 日付を表現するレコード *) | |
type date_t = { | |
month: int; | |
day: int; | |
} | |
(* 人物を表現するレコード *) | |
type person_t = { | |
height: float; | |
weight: float; | |
birthday: date_t; | |
blood: string; | |
} | |
(* 目的:血液型がAの人物の数を返す関数 *) | |
(* count_ketsueki_A : person_t list -> int *) | |
let rec count_ketsueki_A persons = | |
match persons with | |
[] -> 0 | |
| { blood = "A" } :: rest -> 1 + count_ketsueki_A rest | |
| _ :: rest -> 0 + count_ketsueki_A rest;; | |
let people = [{height=1.73; | |
weight=73.2; | |
birthday = { month=10; day=8; }; | |
blood = "A";}; | |
{height = 1.60; | |
weight = 59.2; | |
birthday = { month=12; day=15; }; | |
blood = "A";}; | |
{height = 1.64; | |
weight = 50.4; | |
birthday = { month=8; day=17; }; | |
blood = "O";}; | |
{height = 1.73; | |
weight = 73.2; | |
birthday = { month=1; day=8; }; | |
blood = "A";}; | |
{height = 1.60; | |
weight = 59.2; | |
birthday = { month=2; day=15; }; | |
blood = "A";}; | |
{height = 1.64; | |
weight = 50.4; | |
birthday = { month=3; day=17; }; | |
blood = "O";}; | |
{height = 1.73; | |
weight = 73.2; | |
birthday = { month=4; day=8; }; | |
blood = "A";}; | |
{height = 1.60; | |
weight = 59.2; | |
birthday = { month=5; day=15; }; | |
blood = "A";}; | |
{height = 1.64; | |
weight = 50.4; | |
birthday = { month=6; day=17; }; | |
blood = "O";}; | |
{height = 1.73; | |
weight = 73.2; | |
birthday = { month=7; day=8; }; | |
blood = "A"; }; | |
{height = 1.60; | |
weight = 59.2; | |
birthday = { month=8; day=15; }; | |
blood = "A"; }; | |
{height = 1.64; | |
weight = 50.4; | |
birthday = { month=9; day=17; }; | |
blood = "O"; }; | |
{height = 1.64; | |
weight = 50.4; | |
birthday = { month=11; day=17; }; | |
blood = "O";}];; | |
let count_ketsueki_A1 = count_ketsueki_A people = 8;; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment