这是我必须制作回文函数的代码。在我用来制作回文之前,我已经创建了 listReverse 和 explode 函数。有人可以帮我完成回文函数吗?
let rec listReverse l = match l with
|[] -> []
|head :: tail -> (listReverse tail) @ [head]
(* explode : string -> char list
* (explode s) is the list of characters in the string s in the order in
* which they appear
* e.g. (explode "Hello") is ['H';'e';'l';'l';'o']
*)
let explode s =
let rec _exp i =
if i >= String.length s then [] else (s.[i])::(_exp (i+1)) in
_exp 0
let rec palindrome w =
let a = explode w in
let b = listReverse a in
if c :: d
else false