Skip to content

Instantly share code, notes, and snippets.

@wreulicke
Last active August 10, 2017 10:58
Show Gist options
  • Save wreulicke/0b9035c63106338a80eeedc7d074f4d1 to your computer and use it in GitHub Desktop.
Save wreulicke/0b9035c63106338a80eeedc7d074f4d1 to your computer and use it in GitHub Desktop.
ocaml良さ
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)
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