记录列表上的SML功能
我试图声明一个函数,该函数将元组内的记录列表作为参数,但语法并不像我希望的那样直观。
这就是我想做的:
type Player = {id:int, privateStack:int list};
fun foo(({id, x::xs}:Player)::players, ...) = (* wrong syntax *)
(* do something *)
I'm trying to declare a function that takes a list of records inside a tuple as an argument but the syntax is not as intuitive as I would have liked.
Here's what I'm trying to do:
type Player = {id:int, privateStack:int list};
fun foo(({id, x::xs}:Player)::players, ...) = (* wrong syntax *)
(* do something *)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模式匹配需要将记录字段绑定到某些值,因此您必须使用显式记录语法。因此,
会起作用。
请注意,上述模式匹配并不详尽,请注意
players
的空列表和privateStack
的空列表:Pattern matching requires binding record fields to some values so you have to use explicit record syntax. Therefore,
would work.
Note that above pattern matching is not exhaustive, be aware of empty list for
players
and empty list forprivateStack
: