Created
March 8, 2017 19:19
-
-
Save arthuraa/be64b957d75f07e92c26d8897781a7d0 to your computer and use it in GitHub Desktop.
Heterogeneous lists and get function on them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Require Import Coq.Lists.List. | |
Import ListNotations. | |
Set Implicit Arguments. | |
Unset Strict Implicit. | |
Section hlist. | |
Variable A : Type. | |
Variable B : A -> Type. | |
Inductive hlist : list A -> Type := | |
| HNil : hlist nil | |
| HCons : forall (x : A) (ls : list A), B x -> hlist ls -> hlist (x :: ls). | |
Variable elm : A. | |
Inductive member : list A -> Type := | |
| HFirst : forall ls, member (elm :: ls) | |
| HNext : forall x ls, member ls -> member (x :: ls). | |
Fixpoint hget ls (mls : hlist ls) : member ls -> B elm := | |
match mls with | |
| HNil => fun mem => | |
match mem in member ls' return (match ls' with | |
| nil => B elm | |
| _ :: _ => unit | |
end) with | |
| HFirst _ => tt | |
| HNext _ _ => tt | |
end | |
| HCons x mls' => fun mem => | |
match mem in member ls' return (match ls' with | |
| nil => Empty_set | |
| x' :: ls'' => | |
B x' -> (member ls'' -> B elm) | |
-> B elm | |
end) with | |
| HFirst _ => fun x _ => x | |
| HNext _ mem' => fun _ get_mls' => get_mls' mem' | |
end x (hget mls') | |
end. | |
End hlist. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment