last night I couldn’t fall asleep because I was thinking how sites like Anilist implement their tag-based search systems.
recall that I was faced with the question of “why do we call product types product types, and why do we call sum types sum types?” my intuitive understanding was this:
if you stick to arguments consisting of just zero and one, you’ll end up with “truth” tables that look very similar to those of
AND
andOR
- with multiplication (product) resemblingAND
, and addition (sum) resemblingOR
, with the only difference being that1 + 1 = 2
, unlike1 OR 1
which is equal to1
. but they’re quite similar!
now you might ask “what does this have to do with types mr. liquidex?”
having
OR
-types is really frickin’ weird, because it yields a type system which would allow you to do this (in pseudo-Rust):fn get_string(or: i32 ++ &str) -> Option<&str> { match or { x: &str => Some(x), _ => None, } }
the existence of this
OR
-type would makematch
really weird, as now it could enter multiplematch
arms:fn print_variants(or: i32 ++ &str) { match or { x: i32 => println!("{x}"), x: &str => println!("{x}"), } } fn main() { let t = 123 ++ "many hugs"; print_variants(t); // prints: // 123 // many hugs }
as closing words, I’d just like to say I haven’t looked for any soundness holes in this theoretical type system with
OR
-types. if you find any, feel free to get in touch - I’ll add a note to this post summarizing what’s wrong with my reasoning.