List 如何删除记录字段中的元素?

List 如何删除记录字段中的元素?,list,types,record,sml,ml,List,Types,Record,Sml,Ml,我是SML的新手,我正在从谷歌和stackoverflow上获得的资料中学习 为了好玩,我只是尝试做一些随机的事情,比如: type schedule= { transportation:string, go: string list} val sunday:schedule ={ transportation="Bicycle", go=["gym","walmart","dentist"]} 我想在我访问过他们之后,从我的记录中删除这个地方 fun del("walmart", sund

我是SML的新手,我正在从谷歌和stackoverflow上获得的资料中学习

为了好玩,我只是尝试做一些随机的事情,比如:

type schedule= { transportation:string, go: string list}

val sunday:schedule ={ transportation="Bicycle", go=["gym","walmart","dentist"]}
我想在我访问过他们之后,从我的记录中删除这个地方

fun del("walmart", sunday);=> { transportation="Bicycle", go=["gym","dentist"]}
由此我知道如何从普通列表中删除元素。
我的问题是我不知道如何访问记录中的列表并删除。

您可以使用模式匹配从记录中提取值。您可以执行所需的更改,并构造包含更新值的新记录

例如,如果我有个人记录:

val john = { name = "John", age = 23, country = "Denmark" }
如果我想增加他们的年龄,我可以这样做:

fun updateAge {name, age, country} = { name = name, age = age + 1, country = country }
val john' = updateAge john

因此,简而言之:提取字段,以您知道的方式从列表中删除元素,然后重建记录。

,这样我就可以使用go schedule提取它,并将其传递给另一个名为delete的函数,对吗?非常感谢你。