开发者

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"]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜