2014-12-01 05:16:01 +00:00
|
|
|
prelude
|
2014-06-26 17:59:43 +00:00
|
|
|
inductive nat : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
zero : nat,
|
|
|
|
succ : nat → nat
|
2014-09-04 23:36:06 +00:00
|
|
|
namespace nat end nat open nat
|
2014-06-26 17:59:43 +00:00
|
|
|
|
|
|
|
inductive list (A : Type) : Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
nil {} : list A,
|
|
|
|
cons : A → list A → list A
|
2014-09-17 21:39:05 +00:00
|
|
|
definition nil := @list.nil
|
|
|
|
definition cons := @list.cons
|
2014-06-26 17:59:43 +00:00
|
|
|
|
|
|
|
check nil
|
|
|
|
check nil.{1}
|
|
|
|
check @nil.{1} nat
|
|
|
|
check @nil nat
|
|
|
|
|
2014-09-04 23:36:06 +00:00
|
|
|
check cons nat.zero nil
|
2014-06-26 17:59:43 +00:00
|
|
|
|
|
|
|
inductive vector (A : Type) : nat → Type :=
|
2014-08-22 22:46:10 +00:00
|
|
|
vnil {} : vector A zero,
|
|
|
|
vcons : forall {n : nat}, A → vector A n → vector A (succ n)
|
2014-09-04 23:36:06 +00:00
|
|
|
namespace vector end vector open vector
|
2014-06-26 17:59:43 +00:00
|
|
|
|
|
|
|
check vcons zero vnil
|
2014-10-02 23:20:52 +00:00
|
|
|
constant n : nat
|
2014-06-26 17:59:43 +00:00
|
|
|
check vcons n vnil
|
|
|
|
|
2014-09-04 22:03:59 +00:00
|
|
|
check vector.rec
|
2014-06-26 17:59:43 +00:00
|
|
|
|
|
|
|
definition vector_to_list {A : Type} {n : nat} (v : vector A n) : list A
|
2014-09-04 22:03:59 +00:00
|
|
|
:= vector.rec (@nil A) (fun (n : nat) (a : A) (v : vector A n) (l : list A), cons a l) v
|
2014-06-26 17:59:43 +00:00
|
|
|
|
2015-01-25 04:23:21 +00:00
|
|
|
attribute vector_to_list [coercion]
|
2014-06-26 17:59:43 +00:00
|
|
|
|
2014-10-02 23:20:52 +00:00
|
|
|
constant f : forall {A : Type}, list A → nat
|
2014-06-26 17:59:43 +00:00
|
|
|
|
|
|
|
check f (cons zero nil)
|
|
|
|
check f (vcons zero vnil)
|