Stream: beginners

Topic: when string is


view this post on Zulip Brendan Hansknecht (May 19 2023 at 19:22):

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.

view this post on Zulip Ayaz Hafiz (May 19 2023 at 19:32):

by default the compiler does not do so; optimizations might turn this into a tree comparison though.

view this post on Zulip Brendan Hansknecht (May 21 2023 at 03:36):

What do we do for lists of bytes?
So the same function as above, but ['a', 'a', 'a', ..] or similar?

view this post on Zulip Ayaz Hafiz (May 21 2023 at 04:30):

lists compile to prefix trees


Last updated: Jul 06 2025 at 12:14 UTC