here are fixed-length vectors defined in terms of naturals

Vec: Type → ℕ → Type
Vec A 0 = ⊤
Vec A (S n) = A × Vec A n

nil: (A: Type) → Vec A 0
nil A = ()

cons: (A: Type) → (n: ℕ) → (a: A) → Vec A n → Vec A (S n)
cons A n a as = (a, as) as A × Vec A (S n)

match: (A: Type)
→ (P: (n: ℕ) → Vec A n → Type)
→ P 0 (nil A)
→ ((n: ℕ) → (a: A) → (as: Vec A n)
→ P (S n) (cons A n a as))
→ (n: ℕ) → (Vec A n)
match A P Pn Pc 0 () = Pn
match A P Pn Pc (S n) (a, as) = Pc n a as

I've always thought that vectors are more "complex" than lists because they have a length index but I don't think I can define parametrized, non-indexed lists with only the power of naturals (and maybe equality)

lists in terms of naturals and pairs

List: Type → Type
List A = (n: ℕ) × Vec n A

nil: (A: Type) → List A
nil A = (0, ())

cons: (A: Type) → A → List A → List A
cons A a (n, as) = (S n, (a, as))

Well what do you know! We've got lists

Can I encode W types using nothing but pairs, naturals, and equality? I feel like if it were possible the HoTT book would've already done it
I think there's something more to W types than just naturals. Like okay, lists and vectors are just linear nested tuples, I bet trees can be encoded as branching nested tuples, but W types can have infinite branches, and I don't think that's something I can do

I'm looking at this github.com/UniMath/UniMath/blo and they define W types like this

Definition W := ∑ (X : algebra_ob F), is_initial X.

???

@ionchy Ah yes, the W type is just the initial algebra of a polynomial functor.

A Mastodon instance for users who like the study of programming languages, formal semantics, types, or linguistics.