SML - a small problem
I have given : spacegather : string list -> st开发者_运维技巧ring
I have to make a function, so it turns the call:
spacegather ["I", "am", "nice"] to -> "I am nice"
thanx
intercalate xs xss = concat (intersperse xs xss)
Find the practical meaning of intercalate. Here is intersperse:
(*intersperse x [a,b,c..,z]=>[a,x,b,x,c,x..,x,z]*)
fun intersperse y nil = nil
| intersperse y [x] = [x]
| intersperse y (x::xs)=x::y::(intersperse y xs)
Let me see if i get this right:
fun spacegather (h::[]) = h
| spacegather (h::tl) = h ^ " " ^ (spacegather tl);
spacegather ["I", "am", "nice!!"];
Output: val it = "I am nice!!" : string
This should do it, right?
String.concatWith " " ["I", "am", "nice"]
精彩评论