Re: Little switch improvement: get the used variable
| From: | Lars Strojny | Date: | Fri, 26 Sep 2014 17:41:02 +0000 |
| Subject: | Re: Little switch improvement: get the used variable | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-77683@lists.php.net to get a copy of this message | ||
Hi Rowan,
On 26 Sep 2014, at 18:11, Rowan Collins <rowan.collins@gmail.com> wrote:
[...]
> Without the additional guarantees provided by a purely functional environment, that's
> really just inverting the function header and if statement.
>
> Adding an extra case to that still means repeating the operator, so isn't the same as what
> I was talking about at all:
>
> foo(N) when N>100 ->
> N ** foo(N-10);
>
> foo(N) when N>0 ->
> N * foo(N-1);
>
> foo(0) ->
> 1.
That is true, for the guarding it is indeed syntactic sugar. Sugar that could probably help with
optimisations as it makes reasoning easier from an interpreter perspective but still syntactic
sugar.
>
>> In Scala one could replicate the instanceof behaviour by defining multiple methods of the
>> same name with different argument types.
>
> Or, indeed, in most strongly typed languages; in OOP, polymorphism can be exploited for the
> same purpose, e.g. using the Visitor Pattern. Again, I'm not sure what this has to do with
> switch statements, except that overloading and polymorphism can both allow you to factor out *any*
> if/switch statement, if you so desire.
That is exactly my point: instead of "optimising" the switch/case construct which is good
enough as if/elseif/else replacement I feel our time would be better spent on thinking of
polymorphism, guards and pattern matching.
cu,
Lars
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc