-
-
Save akimacho/ef8d9470520d4098bc16 to your computer and use it in GitHub Desktop.
第9章問題その1
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
(* 第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