Library MonadVM.Support.SeqList
From RocqOfOCaml Require OCamlSeq OCamlIarray OCamlList.
From Stdlib Require Import List.
Import ListNotations.
Set Default Goal Selector "!".
From Stdlib Require Import List.
Import ListNotations.
Set Default Goal Selector "!".
Mapping the finite array before constructing its sequence preserves the
sequence, while making recursive calls visible to the guard checker.
Lemma iarray_to_seq_map {A B : Set} (f : A → B) (xs : list A) :
OCamlIarray.to_seq (OCamlIarray.map f xs) =
OCamlSeq.map f (OCamlIarray.to_seq xs).
Proof.
unfold OCamlIarray.to_seq, OCamlIarray.map.
induction xs as [|x xs IH].
- reflexivity.
- cbn [OCamlIarray.map List.map OCamlIarray.to_seq OCamlSeq.of_list OCamlSeq.map] in ×.
now rewrite IH.
Qed.
OCamlIarray.to_seq (OCamlIarray.map f xs) =
OCamlSeq.map f (OCamlIarray.to_seq xs).
Proof.
unfold OCamlIarray.to_seq, OCamlIarray.map.
induction xs as [|x xs IH].
- reflexivity.
- cbn [OCamlIarray.map List.map OCamlIarray.to_seq OCamlSeq.of_list OCamlSeq.map] in ×.
now rewrite IH.
Qed.
The direct-list form exposes the original array elements to Rocq's
structural recursion checker; the sequence form allocates an intermediate
spine before mapping the recursive call.
Lemma of_seq_map_append_singleton {A B : Set}
(f : A → B) (xs : list A) (last : B) :
OCamlList.of_seq
(OCamlSeq.append (OCamlSeq.map f (OCamlIarray.to_seq xs))
(OCamlSeq.singleton last)) = List.map f xs ++ [last].
Proof.
induction xs as [|x xs IH].
{ reflexivity. }
cbn [OCamlIarray.to_seq OCamlSeq.of_list OCamlSeq.map
OCamlSeq.append OCamlList.of_seq OCamlSeq.to_list List.map app] in ×.
f_equal. exact IH.
Qed.
(f : A → B) (xs : list A) (last : B) :
OCamlList.of_seq
(OCamlSeq.append (OCamlSeq.map f (OCamlIarray.to_seq xs))
(OCamlSeq.singleton last)) = List.map f xs ++ [last].
Proof.
induction xs as [|x xs IH].
{ reflexivity. }
cbn [OCamlIarray.to_seq OCamlSeq.of_list OCamlSeq.map
OCamlSeq.append OCamlList.of_seq OCamlSeq.to_list List.map app] in ×.
f_equal. exact IH.
Qed.