Fixpoint pos (X : Type) (d : forall x y : X, {x = y} + {x <> y}) (x : X) l : option nat :=
  match l with
  | nil => None
  | y :: l => if d x y then Some 0 else match pos d x l with Some f => Some (S f) | None => None end
  end.

(* Specifications: *)
Lemma el_pos X d (x : X) l : x el l -> exists n, pos d x l = Some n.
Lemma pos_nth X d (x : X) l n def : pos d x l = Some n -> nth n l def = x.
Lemma pos_length X d (x : X) l n : pos d x l = Some n -> n < | l |.