16 Aug 2012 18:13
Re: Signature of Abstract Methods
On Wed, Aug 15, 2012 at 10:35 PM, Seyed H. HAERI (Hossein) <hossein.haeri@...> wrote: > Hi Alex, > > > This is a method, which, when invoked, performs the computation, > rather than returning a function value. > > I see. > > > Methods can be turned into functions automatically (through eta > expansion) but they're not equivalent. > > OK, then, I need to ask what functions are in Scala? I was always > under the impressions that there are no free functions in Scala and > all functions are methods. I seem to understand now that that's wrong. > Would you mind correcting me? You are mostly correct. Every code executed in Scala is inside a method or a contructor, no exception. However, Scala hides this for certain cases. Specifically, there are traits called Function0 through Function22, which implement the concept of a function as an object. Scala supports them in various ways: * The method "apply" can be omitted, so obj.apply(params) can be written as obj(params) * There's syntax for anonymous functions, so that, for example, "(x: Int) => x * 2" automatically creates an instance of the trait Function1 with an apply method implemented accordingly.(Continue reading)
RSS Feed