reverse はリストを逆順にする。
# let rec reverse l = match l with [] -> [] | hd::tl -> (reverse tl) @ [hd] ;; val reverse : 'a list -> 'a list = <fun> # reverse [1;2;3;4;5];; - : int list = [5; 4; 3; 2; 1]
takatoh's blog – Learning programming languages.
reverse はリストを逆順にする。
# let rec reverse l = match l with [] -> [] | hd::tl -> (reverse tl) @ [hd] ;; val reverse : 'a list -> 'a list = <fun> # reverse [1;2;3;4;5];; - : int list = [5; 4; 3; 2; 1]