checking whether mutable list has cycle in ocaml?
问题 I'm trying to write a function to test whether a mutable list in Ocaml contains a cycle or not (that is, has a reference to itself and repeats continuously. My list is defined as type 'a m_list = Nil | Cons of 'a * (('a m_list) ref) . So far, I have: 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 ;; but it's not quite right and I'm unsure how to proceed from here...thanks for