【发布时间】:2011-07-24 21:20:05
【问题描述】:
我正在尝试编写一个函数来测试 Ocaml 中的可变列表是否包含循环(即具有对自身的引用并不断重复。
我的列表定义为type 'a m_list = Nil | Cons of 'a * (('a m_list) ref)。
到目前为止,我有:
let is_cyclic list =
let rec check xs =
match (!xs) with
|Nil -> false
|Cons(_,v) -> ((!v)==list)||check v in
match list with
|Nil -> false
|Cons(_, x) -> check x ;;
但这不太正确,我不确定如何从这里开始...感谢您的帮助!
【问题讨论】: