Vec Lemmas #
TODO: Header
Fun.Vec.to #
to #
append #
list #
@[simp]
length #
Vec carries its own length, hence why length is marked reducible. This also means that most operations on length are trivial and the simplifier will reject them.
get #
head #
tail #
set #
foldl #
foldr #
concat #
flatten #
map #
Why don't we use Functor / LawfulFunctor?
Because Lean's type inference is not capable of figuring out the right functor f when
using Functor.map.
Try it yourself: implement Functor (Vec · n) and notice how (· + 2) <$> #(1, 2) fails.
Solutions:
- Try to fix Lean's type inference algorithm, unclear if Lean developers will be receptive
- Use
Vec.mapdirectly (not horrible,v.map fis good ergonomics) - Define our own
IndexedFunctortype that will resolve the index correctly:
class IndexedFunctor (I : Type u) (F : Type v -> I -> Type w) where
imap {α β i} (f : α -> β) : F α i -> F β i
instance : IndexedFunctor Nat Vec where
imap := Vec.map
#eval IndexedFunctor.imap (· + 2) #(1, 2)
For now we choose 2