ocamlで文字列を1文字ずつのリストにする
昨日、pythonとrubyについて書いたので、ocamlでどう書くか調べてみた。
こんな感じか
(* 文字列を1文字ずつ分割してstring listにして返す*) (* split_string : string -> string list *) let split_string s = Str.split (Str.regexp "") s;; (* test *) let test1 = split_string "" = [] let test2 = split_string "a" = ["a"] let test3 = split_string "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" = ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"; "k"; "l"; "m"; "n"; "o"; "p"; "q"; "r"; "s"; "t"; "u"; "v"; "w"; "x"; "y"; "z"; "A"; "B"; "C"; "D"; "E"; "F"; "G"; "H"; "I"; "J"; "K"; "L"; "M"; "N"; "O"; "P"; "Q"; "R"; "S"; "T"; "U"; "V"; "W"; "X"; "Y"; "Z"; "0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"]