Fixpoint intersectionPairs
  {A     : Set}
  (f     : A -> list A -> option A)
  (ea eb : list A)
: list (A * A) :=
  match ea with
  | nil => nil
  | cons a ea_rest =>
    match f a eb with
    | Some r => (a, r) :: intersectionPairs f ea_rest eb
    | None   =>           intersectionPairs f ea_rest eb
    end
  end.
