Stream: beginners

Topic: List Slicing/Pattern Matching?


view this post on Zulip Declan Joseph Maguire (Oct 11 2023 at 10:20):

I see going through old streams that a lot of stuff has gone into list slicing and pattern matching. However, I'm unsure if the pattern matching is up to date in the tutorial, or if its outdated. Good slicing is always appreciated.

Additonally, is there a way to deconstruct a list such that you can break it into lists and elements? Like, matching a list so you could split it into two sublists based on some criteria? We can think of lists as closed under concatenation, so in a sense they're recursive structures. If it doesn't exist, I feel it should, though I'm already thinking about how it'd be a delicate matter to not become either ambiguous or over-complex. If no-one's done it, and it's not absurdly stupid, I might think on it longer and create a proper proposal. I can see it doing some magic things with in-place mutation optimisations, plus it might be extensible to other structures like trees and so on.

Dunno. The beauty of pattern matching seems to be in letting you assign names directly to the bits of a thing you want to process, rather than doing a bunch of error-prone extractive nonsense, and it'd be a shame not to extend that as far as Roc's design goals allow.

view this post on Zulip Anton (Oct 11 2023 at 11:30):

Some element focused pattern matching is supported. But I believe we do not support haskell style x:xs pattern matching yet. We have talked about it before, I'll see if I can find it.

view this post on Zulip Anton (Oct 11 2023 at 11:37):

Found it
We also have an issue for it.


Last updated: Jul 06 2025 at 12:14 UTC