Last active
August 10, 2017 10:58
-
-
Save wreulicke/0b9035c63106338a80eeedc7d074f4d1 to your computer and use it in GitHub Desktop.
ocaml良さ
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 'a myList = MyNil | MyCons of 'a * 'a myList | |
let rec print_mylist l = | |
match l with | |
| MyCons(head, tail) -> | |
print_string(head); | |
print_mylist(tail); | |
| MyNil -> print_string("nil") | |
let () = | |
print_mylist (MyCons("xxx", MyNil)) | |
let () = | |
print_mylist (MyNil) |
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 'a myList = MyNil | MyCons of 'a * 'a myList | |
let rec map f x = | |
match x with | |
| MyNil -> MyNil | |
| MyCons (x, xs) -> | |
MyCons (f x, map f xs); | |
;; | |
map print_string MyNil | |
;; | |
map print_string (MyCons("xxx", MyNil)) | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment