Hi everyone,

On 24 Sep 2014, at 23:17, Rowan Collins <rowan.coll...@gmail.com> wrote:

> switch ( $number ) use ( === ) {
[...]
> switch ( $age ) use ( < ) {
[...]
> switch ( calculate_age($birth_date, $departure_date) as $age_at_departure ) 
> use ( < ) {
[...]
> switch ( $product ) use ( instanceOf ) {

All of these examples are trying to reinvent concepts that can be solved with 
guards, pattern matching and overloading in other languages. In Erlang one can 
write the same function name multiple times and guard it ("when" in fact(N)) or 
match the value ("0" in fact(0)).

fact(N) when N>0 ->
    N * fact(N-1);

fact(0) ->
    1.

In Scala one could replicate the instanceof behaviour by defining multiple 
methods of the same name with different argument types.

So I would rather see us making method declarations more flexible to cover 
those use cases instead of shoving all the functionality into switch/case. Last 
time I checked the interpreter to try and introduce more features around method 
declarations, it looks incredibly hard to do in a way that performs well. What 
is our stance on adding advanced features around declaring methods?

cu,
Lars

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to