2010-10-10 67 views
1

:spacegather:字符串列表 - >字符串SML - 我給了一個小問題

我必須做出一個功能,所以它把呼叫:

spacegather [ 「我」, 「上午」, 「好」],以 - > 「我很漂亮」

感謝名單

+0

請看問題[關於foldr相似SML問題(http://stackoverflow.com/questions/3900369/sml-question-about-foldr),這是由另一名學生在同一個分配工作大概問。 – sepp2k 2010-10-10 14:22:16

回答

0

讓我看看,如果我得到這個權利:

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

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

輸出:VAL它= 「我很好!」 :string

這應該這樣做吧?

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) 
0
String.concatWith " " ["I", "am", "nice"]