3 ms·
Other than the ability to put a predicate in the pattern position (which you can do in several languages, including Haskell with ViewPatterns), I still don't se
by oisdk 7y ago
Other than the ability to put a predicate in the pattern position (which you can do in several languages, including Haskell with ViewPatterns), I still don't see what Perl 6 adds here? Of course it's more difficult to model the problem using sum types, but there's an asymmetry here: whereas given can't do powerful pattern-matching features like exhaustiveness checking, GADTs, auto case-split in an IDE, efficient case trees, etc., the opposite isn't true. Haskell can do everything Perl does here, just by using strings! The other features (multiple variables to split on) are pretty standard these days.
vosotros = ["Spain", "EquitorialGuinea", "WesternSahara"]
message = case (number, gender, formality, country) of
(1 , "masculine" , "informal", _ ) -> "¿Cómo estás mi amigo?"
(1 , "masculine" , "formal" , _ ) -> "¿Cómo está el señor?"
(1 , "feminine" , "informal", _ ) -> "¿Cómo estás mi amiga?"
(1 , "feminine" , "formal" , _ ) -> "¿Cómo está la señora?"
((> 1) -> T, (`elem` ["mixed","masculine"]) -> T, "informal", (`elem` vosotros) -> T) -> "¿Cómo estáis mis amigos?"
((> 1) -> T, "feminine" , "informal", (`elem` vosotros) -> T) -> "¿Cómo estáis mis amigas?"
((> 1) -> T, _ , _ , _ ) -> "¿Cómo están ustedes?"