Hi Rowan, On 26 Sep 2014, at 18:11, Rowan Collins <rowan.coll...@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
signature.asc
Description: Message signed with OpenPGP using GPGMail