我想编写一个函数,将值 v 插入到位置 a 的列表中。列表的类型是
type RefList<'t> = Item<'t> ref
and Item<'t> = | Nil | Cons of 't * RefList<'t>
let rec insert<'t> (a: int) (v: <'t>) (structure: RefList<'t>): unit =
和
let rec remove<'t> (a: int) (structure: RefList<'t>): unit =
我尝试过这样的事情,但我确定我走错了路
let mutable worker = 0
if a = worker then then Cons(v, !structure) else Cons(y, insert i v ys)
worker <- worker + 1
我不确定我是否应该匹配 |Nil 和 |Cons。“单位”让我感到困惑。
我希望有人可以帮助我,谢谢!
编辑:我已经有一个函数 RefListToList 和 ListToRefList。这可能对其他功能有用