If I write a when over strings, will it use a tree for smart matching?
when str is
"aaa" -> ...
"aab" -> ...
"ac" -> ...
_ -> ...
Essentially would be above code generate a character by character tree based match. So if the first character isn't a
, it will just go straight to the _
case.
by default the compiler does not do so; optimizations might turn this into a tree comparison though.
What do we do for lists of bytes?
So the same function as above, but ['a', 'a', 'a', ..]
or similar?
lists compile to prefix trees
Last updated: Jul 06 2025 at 12:14 UTC