Create a gist now

Instantly share code, notes, and snippets.

@akimacho /09
Last active Aug 29, 2015

Embed
第9章問題その1
(* 第9章問題*)
(* 問題9.1 *)
# "春" :: "夏" :: "秋" :: "冬" :: [] ;;
- : string list = ["春"; "夏"; "秋"; "冬"]
# "春" :: ("夏" :: ("秋" :: ("冬" :: []))) ;;
- : string list = ["春"; "夏"; "秋"; "冬"]
(* ↓ではダメ.定義からはずれてしまう *)
# "春" :: "夏" :: "秋" :: "冬" ;;
Error: This expression has type string but an expression was expected of type
string list
(* 問題9.2 *)
# type person_t = {
name : string;
height : float;
weight : float;
birth_day : int * int;
blood : string;
};;
# let o1 =
{name = "hoge"; height = 180.; weight = 80.; birth_day = (1, 1);
blood = "A"};;
# let o2 =
{name = "foo"; height = 150.; weight = 35.; birth_day = (3, 17);
blood = "AB"};;
# let o3 =
{name = "piyo"; height = 170.; weight = 60.; birth_day = (10, 28);
blood = "O"};;
# o1 :: o2 :: o3 :: [] ;;
- : person_t list =
[{name = "hoge"; height = 180.; weight = 80.; birth_day = (1, 1);
blood = "A"};
{name = "foo"; height = 150.; weight = 35.; birth_day = (3, 17);
blood = "AB"};
{name = "piyo"; height = 170.; weight = 60.; birth_day = (10, 28);
blood = "O"}]
(* 問題9.3 *)
["春"; "夏"; "秋"; "冬"] ;;
- : string list = ["春"; "夏"; "秋"; "冬"]
(* 勘違いして↓のように打つと *)
["春", "夏", "秋", "冬"] ;;
- : (string * string * string * string) list = [("春", "夏", "秋", "冬")]
[o1; o2; o3] ;;
- : person_t list =
[{name = "hoge"; height = 180.; weight = 80.; birth_day = (1, 1);
blood = "A"};
{name = "foo"; height = 150.; weight = 35.; birth_day = (3, 17);
blood = "AB"};
{name = "piyo"; height = 170.; weight = 60.; birth_day = (10, 28);
blood = "O"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment