1

我给了:spacegather:字符串列表->字符串

我必须创建一个函数,所以它会调用:

spacegather ["I", "am", "nice"] 到 -> "I am nice"

谢谢

4

3 回答 3

2
intercalate xs xss = concat (intersperse xs xss)

找出intercalate的实际意义。这里是穿插的:

(*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)
于 2010-10-13T02:59:17.080 回答
1

让我看看我是否做对了:

fun spacegather (h::[]) = h 
| spacegather (h::tl) = h ^ " " ^ (spacegather tl);

spacegather ["I", "am", "nice!!"];

输出: val it = "我很好!!" : 细绳

这个应该可以吧?

于 2011-07-14T23:18:32.393 回答
0
String.concatWith " " ["I", "am", "nice"]
于 2011-08-30T21:57:09.900 回答