SML - 一个小问题

时间:2010-10-10 14:18:27

标签: sml

我已经给出:spacegather:string list - >串

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

spacegather [“I”,“am”,“nice”] to - > “我很高兴”

感谢名单

3 个答案:

答案 0 :(得分:2)

intercalate xs xss = concat (intersperse xs xss)

找到插入的实际意义。这是散布的:

(*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)

答案 1 :(得分:0)

让我看看我是否做对了:

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

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

输出:val it =“我很好!!” :string

这应该这样做,对吧?

答案 2 :(得分:0)

String.concatWith " " ["I", "am", "nice"]