Lean4
/-- Given a productive weak sequence, we can collapse all the `think`s to
produce a sequence. -/
def toSeq (s : WSeq α) [Productive s] : Seq α :=
⟨fun n => (get? s n).get, fun {n} h =>
by
cases e : Computation.get (get? s (n + 1))
· assumption
have := Computation.mem_of_get_eq _ e
simp only [get?] at this h
obtain ⟨a', h'⟩ := head_some_of_head_tail_some this
have := mem_unique h' (@Computation.mem_of_get_eq _ _ _ _ h)
contradiction⟩