Zulip Chat Archive
Stream: new members
Topic: vector type
Jalex Stark (May 02 2020 at 20:23):
Brandon Brown said:
Hoping someone help me understand the
vector α n
type . It's supposed to be a kind of list of typeα
of lengthn
but I don't see how this type enforces the length to ben
inductive vector (α : Type u) : nat → Type u | nil {} : vector zero | cons {n : ℕ} (a : α) (v : vector n) : vector (succ n)
I'm not really sure how to use this type.
it enforces the length to b n by induction. You can see an n on the LHS and a succ n on the RHS
Jalex Stark (May 02 2020 at 20:24):
what do you want to do with vector?
Brandon Brown (May 02 2020 at 20:26):
So if I do vector.cons ℕ vector.nil
that creates a type within the vector type family?
Brandon Brown (May 02 2020 at 20:26):
I'm still wrapping my head around the inductive family thing
Jalex Stark (May 02 2020 at 20:33):
vector 3
is a type
Brandon Brown (May 02 2020 at 20:35):
How do I create a vector of natural numbers of length e.g. 2?
Jalex Stark (May 02 2020 at 20:37):
def v : vector ℤ 3 := vector.cons (-1 : ℤ) (vector.cons (0) (vector.cons 0 vector.nil))
#print v
Jalex Stark (May 02 2020 at 20:39):
the notation that comes out of the print is also a valid thing to put in
Brandon Brown (May 02 2020 at 20:40):
Hm ok so that created the type, now how do I add elements to it?
like for list you just keep doing list.cons h (list.cons h (list.nil)))
or whatever
Brandon Brown (May 02 2020 at 20:41):
But in this case its supposed to limit it to length 3
Brandon Brown (May 02 2020 at 20:47):
Oh you already added elements - oh man I'm really confused
Brandon Brown (May 02 2020 at 20:49):
Ohh I get it now - thanks
Last updated: Dec 20 2023 at 11:08 UTC