peter81
peter81

Reputation: 31

SML - a small problem

I have given : spacegather : string list -> string

I have to make a function, so it turns the call:

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

thanx

Upvotes: 1

Views: 254

Answers (3)

newacct
newacct

Reputation: 122538

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

Upvotes: 0

Bernd
Bernd

Reputation: 2209

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?

Upvotes: 1

frayser
frayser

Reputation: 1782

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)

Upvotes: 2

Related Questions