logoalt Hacker News

TheNumbat • yesterday at 9:45 PM • 1 reply • view on HN

Yeah, I'm aware, but wanted to avoid the complexity.


Replies

Ericson2314 • yesterday at 10:04 PM

I don't think you want to avoid this complexity:

- OOP is existential types where the layouts share some sort of shared prefix (e.g. pointer to vtable, fields in common, etc.). To accurately model such things (and they occur in FFI), you need to separate types from layout, and hold the "supertype's layout" fixed.

- A classic use-case of dependent types is dynamically-sized arrays, and "tensors". When you have a pair (L: Nat, V: Pointer(Array(N, T))), you have a layout behind the pointer that is dynamic, but you don't want to conflate this with arbitrary types of the pointee.

Failure to deal with this in fully generality will force you to go down Rust's path of ad-hoc arrays and "dyn trait", which is actually more complexity.

➕ show 1 reply