14th October Lambdas Hackday

Richard Warburton richard.warburton at gmail.com
Mon Oct 22 01:53:09 PDT 2012


> Until we get coroutines (there is a patch in mlvm workspace for that)
> the answer seems to be that there is no good way to express a generator
> function.

Entirely reasonable and I dont think people will be expecting this anytime
soon.

> > 2. The design of flatMap confused a lot of people.  They didn’t seem
> > to understand the callback was a block.  It was much easier to explain
> > the intended purpose via an example than anything else.  It might
> > simply be the case that ‘Block’ is a bad name for result callback
> > handler, though I appreciate that people wish to avoid interface
> > proliferation.
> > 3. People didn’t understand why Stream.fold() takes both a Combiner
> > and a BinaryOp, rather than just a combiner.
> > 4. Any code that relies on getClass() is hard to transform from an
> > anonymous inner class into a lambda.  This is because getClass() on a
> > lambda returns the class that it was defined within, rather than the
> > class of the anonymous inner class.  It makes sense from the
> > perspective of lambdas being like blocks - but it will break things
> > down the line so there should probably be at least a “Beware!” type
> > warning.
>
> The issue is more general that just getClass().
> 'this' in an anonymous class refers to the anonymous class instance
> and 'this' in a lambda refers to the enclosing class.
> So beware when you retrofit an anonymous class to a lambda.
>
> For newbie that doesn't know what an anonymous class is but are exposed
> to the inner class syntax, e.g. most of my students before my course,
> they often think that 'this' in an anonymous class refers to the
> enclosing class,
> and no the anonymous hidden class so if we have to put a warning
> somewhere and I don't think so,
> it should be in inner classes, not in lambda.

Sure.  The point is that getClass() is where people found things
confusing.  Overall people seemed to find using this to refer to the
surrounding class to be entirely natural.  Obviously it does add conceptual
overhead to translating from inner classes, but not too bad of an overhead.

regards,

  Richard


More information about the lambda-dev mailing list