This file contains hidden or 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
(* 目的:ふたつのリストを受け取って長さが同じかどうかを返す *) | |
(* equal_length : a' list -> b' list -> bool *) | |
let rec equal_length lst1 lst2 = | |
match lst1 with | |
[] -> (match lst2 with [] -> true | _::_ -> false) | |
| f1::r1 -> (match lst2 with [] -> false | f2::r2 -> equal_length r1 r2) | |
(* テスト *) | |
let test1 = equal_length [] [] = true | |
let test2 = equal_length [1; 2; 3] ["a";"b";"c"] = true |
This file contains hidden or 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 = { | |
name : string; | |
height : float; | |
weight : float; |
This file contains hidden or 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 = { | |
name : string; | |
height : float; | |
weight : float; |
This file contains hidden or 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 rec gakusei_max_new lst = match lst with | |
[] -> { name = "void"; tensuu = 0; seiseki = "0"; } | |
| first :: rest -> let max = gakusei_max rest in | |
if (first.tensuu > max.tensuu) | |
then first | |
else max |
This file contains hidden or 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 gakusei_t = {name: string; tensuu: int; seiseki: string} | |
(*学生データのリスト*) | |
let gakusei1 = { name = "asai"; tensuu = 70; seiseki = "B"; } | |
let gakusei2 = { name = "kaneko"; tensuu = 85; seiseki = "A"; } | |
let gakusei3 = { name = "yoshida"; tensuu = 80; seiseki = "A"; } | |
let gakusei4 = { name = "x-asai"; tensuu = 70; seiseki = "B"; } | |
let gakusei5 = { name = "x-kaneko"; tensuu = 85; seiseki = "A"; } | |
let gakusei6 = { name = "x-yoshida"; tensuu = 80; seiseki = "A"; } |
This file contains hidden or 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
(* 10.2 目的:任意の整数のリストから昇順に整列したリストを返す *) | |
(* ins_sort : int list -> int list *) | |
let rec ins_sort lst = match lst with | |
[] -> [] | |
| first :: rest -> insert (ins_sort rest) first | |
(* テスト *) | |
let test2_1 = ins_sort [] = [] | |
let test2_2 = ins_sort [3;5;1] = [1;3;5] | |
let test2_3 = ins_sort [5;3;8;1;7;4] = [1;3;4;5;7;8] |
This file contains hidden or 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 src = [1;2;3;1;3] | |
(* 0〜max までのリスト *) | |
let rec nums_in m lst = | |
if m >= 0 | |
then nums_in (m-1) (m::lst) | |
else lst | |
let nums m = nums_in m [] | |
This file contains hidden or 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
(* ex 8.3 *) | |
type date_t = { | |
month: int; | |
day: int; | |
} | |
type person_t = { | |
height: float; | |
weight: float; | |
birthday: date_t; |
This file contains hidden or 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
(* 月、日を入力して星座をもとめる *) | |
(* | |
牡羊座 Aries 3月21日から4月20生まれ | |
牡牛座 Taurus 4月21日から5月20生まれ | |
双子座 Gemini 5月21日から6月21日生まれ | |
蟹座 Cancer 6月22日から7月23日生まれ | |
獅子座 Leo 7月24日から8月23日生まれ | |
乙女座 Virgo 8月24日から9月23日生まれ | |
天秤座 Libra 9月24日から10月23日生まれ |
NewerOlder