You're omitting a lot of context here, and I had to remove references to missing modules in order to reproduce, which means I've made several assumptions that may be wrong.
Given that, my guess is that you've copied code that originally used the Base or Core standard library replacement, where the List.nth
function returns an 'a option
, as opposed to the standard OCaml implementation which will raise an exception instead if the given index is out of bounds.
The reason I think so is that the parent
field of dec
has type dec option
and is assigned last_scope
directly, which means last_scope
must have the same type. And if List.nth
has type 'a list -> int -> 'a
, then 'a
must have type dec option
, which means table
must have type dec option list
. And you can't prepend a dec
to a dec option list
, hence the error.
Lastly, a good way to find the cause of issues like this is to make your assumptions explicit by annotating the type of variables. For example, annotating the type of table
here will give you a different error, narrowing it down last_scope
having the type dec
but being expected to have type dec option
when being assigned to parent
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…