Skip to content

Instantly share code, notes, and snippets.

@sugitach
Last active August 29, 2015 14:06
Show Gist options
  • Save sugitach/aec120066998a0ab1397 to your computer and use it in GitHub Desktop.
Save sugitach/aec120066998a0ab1397 to your computer and use it in GitHub Desktop.
ex-8
(* ex 8.3 *)
type date_t = {
month: int;
day: int;
}
type person_t = {
height: float;
weight: float;
birthday: date_t;
blood: string;
}
let p1 = {
height=1.73;
weight=73.2;
birthday={ month=10; day=8; };
blood="A";
}
let p2 = {
height=1.60;
weight=59.2;
birthday={ month=12; day=15; };
blood="A";
}
let p3 = {
height=1.64;
weight=50.4;
birthday={ month=8; day=17; };
blood="O";
}
(* ex 8.1 *)
type book_t = {
title: string;
auther: string;
publisher: string;
price: int;
isbn: string;
}
let b1 = {
title= "この本";
auther= "知らん人";
publisher= "わからん会社";
price= 500;
isbn= "ISBN902-4-6677-6655-1";
}
let b2 = {
title= "あの本";
auther= "知人";
publisher= "某出版社";
price= 1280;
isbn= "ISBN902-4-6677-6655-2";
}
let b3 = {
title= "キタ━━━━━(゚(゚∀(゚∀゚(☆∀";
auther= "だれ?";
publisher= "町の電気屋さん";
price= 329;
isbn= "ISBN902-4-6677-6655-3";
}
(* ex 8.2 *)
type okozukai_t = {
name: string;
price: int;
shop: string;
date: string;
}
let o1 = {
name= "鉛筆";
price= 80;
shop= "文房具屋";
date= "2014-09-18";
}
let o2 = {
name= "パソコン";
price= 128000;
shop= "電気屋";
date= "2014-07-18";
}
let o3 = {
name= "一戸建て";
price= 42500000;
shop= "不動産屋";
date= "2014-08-18";
}
(* ex 8.5 *)
type ekimei_t = {
kanji: string;
kana: string;
romaji: string;
shozoku: string;
}
(* ex 8.6 *)
(* ekimei_t を受け取って「路線名、駅名(かな)」の形式で出力する *)
(* hyoji ekimei_t -> string *)
let hyoji ekimei = match ekimei with
{ kanji = kanji;
kana = kana;
romaji = romaji;
shozoku = shozoku;
} -> shozoku ^ ", " ^ kanji ^ "(" ^ kana ^ ")"
let ex1 = hyoji {kanji = "茗荷谷"; kana = "みょうがだに"; romaji = "myogadani"; shozoku = "丸の内線"}
= "丸の内線, 茗荷谷(みょうがだに)"
(* ex 8.7 *)
type ekikan_t = {
kiten: string;
shuten: string;
keiyu: string;
kyori: float;
jikan: int;
}
(* なんで、以下じゃない? *)
type ekikan_t = {
kiten: ekimei_t;
shuten: ekimei_t;
keiyu: string;
kyori: float;
jikan: int;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment