Skip to content

Instantly share code, notes, and snippets.

@wilcoxjay
Created April 8, 2015 18:12
Show Gist options
  • Save wilcoxjay/7793370578da8154472b to your computer and use it in GitHub Desktop.
Save wilcoxjay/7793370578da8154472b to your computer and use it in GitHub Desktop.
Nonempty list safe head
Require Import List.
Import ListNotations.
Section nelist.
Variable (A : Type).
Definition nelist : Type := {l : list A | l <> nil}.
Definition safe_head (l : nelist) : A.
refine (match proj1_sig l as y' return y' <> [] -> _ with
| [] => fun H => _
| x :: l' => fun _ => x
end _).
- congruence.
- exact (proj2_sig l).
Defined.
End nelist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment