3 ms·
Oddly, at the totally other end of the type-system spectrum, the "wantarray" feature of Perl allows you to implement this behavior yourself for a subset (two, i
by zbentley 9y ago
Oddly, at the totally other end of the type-system spectrum, the "wantarray" feature of Perl allows you to implement this behavior yourself for a subset (two, in this case) of Perl's main data types* .
http://perldoc.perl.org/functions/wantarray.html http://perldoc.perl.org/functions/wantarray.html
You have to wire it up yourself, and it happens at runtime (because most everything interesting in Perl does) but your function can alter its return type from a scalar to a vector (list, in Perl parlance. Pearlance? Nevermind) based on the way in which it is invoked.
I've seen this used for great evil and great good, but regardless: it's an interesting case in point that such features can be present (albeit in really different forms) and useful even in languages that bear very little resemblance to Haskell/Rust/etc.
*contexts, in this case, but it allows for equivalent behavior to return-type polymorphism in a very limited way.
Edit: formatting.