Daily Thought - 2024-08-21
< back to listIf you've been reading my thoughts on pattern-matching functions over the last few days, you might wonder if this isn't a bit of an overloaded concept, and if it might be better to split it into two simple and orthogonal ones: Functions without pattern matching, and a standalone pattern matching expression. At least that's what I thought when I was writing it.
But if you sit down to implement that, you might notice that the branches of a match expression are pretty similar to anonymous functions. And then you're left with a dilemma: Re-use anonymous functions to represent match branches, or include an almost-like-a-function-but-not-quite thing as part of match expressions. At least that's what happened to me.
The latter option is kinda out. If match expressions contain almost-functions, then they aren't really orthogonal to functions. This defeats the whole point of having two orthogonal concepts. But reusing functions won't work, for the same reason that sent me down this road in the first place: It means multiple branches can't capture the same linear value.