4 ms·
> arrays of alternating functions and regexps many languages will allow you to succinctly express the concept of "the type of this element is a or b" e.g. typ
by SideburnsOfDoom 5y ago
> arrays of alternating functions and regexps
many languages will allow you to succinctly express the concept of "the type of this element is a or b"
e.g. typescript:
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types https://www.typescriptlang.org/docs/handbook/2/everyday-type...
Rust:
https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
F# :
https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/discriminated-unions https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
IDK, allowing that kind of type to be declared seems like a good thing to me? Those links have good examples of where it's useful. You'd need a good reason to use actually "function or regexp" in actual code though.
- bmn__ 5y agoYou have misunderstood GP. Alternating functions and regexps looks like this: [\&some_function, qr/some_regex/, \&another_function, qr/another_regex/] This is distinct from the idea of sum types.
- SideburnsOfDoom 5y agoOh, I get that their example said _alternating_ function and regex. If that's the real requirement then they shouldn't be _alternating_ in the list at all, there should be a list of (function, regex) tuples. We don't need an example of tuples, they're even more widespread than sum types / unions / enums. So the design as stated is very contrived, to the point where it doesn't make sense, but existing constructs can be used to make sense of it with a change one way or the other.
- hedora 5y agoSum types are great, but neither perl nor python let you statically check that they're being used properly.