SML——一个小问题

发布于 2024-09-27 00:24:26 字数 146 浏览 7 评论 0原文

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

我必须创建一个函数,因此它将调用:

spacegather ["I", "am", "nice"] 转换为 -> “我很好”

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

∝单色的世界 2024-10-04 00:24:26
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)
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)
终止放荡 2024-10-04 00:24:26

让我看看我是否做对了:

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

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

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

这应该可以吧?

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?

仄言 2024-10-04 00:24:26
String.concatWith " " ["I", "am", "nice"]
String.concatWith " " ["I", "am", "nice"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文