- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
top-level functions in a package
Sun, 2009-02-01, 05:41
I am just starting to learn Scala. It doesn't seem to let me put top-level functions (i.e., regular functions that are not methods of a class) in a package. Am I missing something? I can't find anything about it in the Odersky book. Thanks.
Russ P.
--
http://RussP.us
Russ P.
--
http://RussP.us
Sun, 2009-02-01, 06:17
#2
Re: top-level functions in a package
On Jan 31, 2009, at 8:41 PM, Russ Paielli wrote:
> I am just starting to learn Scala. It doesn't seem to let me put top-
> level functions (i.e., regular functions that are not methods of a
> class) in a package.
Right. It inherits this from Java — there are no bare functions, only
methods of classes.
If you need a standalone function, use the 'object' keyword to declare
a singleton object and make it a method of that.
—Jens
Sun, 2009-02-01, 10:37
#3
Re: top-level functions in a package
or an object extending FunctionN and then implement the apply() method and voilá?
On Sun, Feb 1, 2009 at 6:04 AM, Jens Alfke <jens@mooseyard.com> wrote:
--
Viktor Klang
Senior Systems Analyst
On Sun, Feb 1, 2009 at 6:04 AM, Jens Alfke <jens@mooseyard.com> wrote:
On Jan 31, 2009, at 8:41 PM, Russ Paielli wrote:
I am just starting to learn Scala. It doesn't seem to let me put top-level functions (i.e., regular functions that are not methods of a class) in a package.
Right. It inherits this from Java — there are no bare functions, only methods of classes.
If you need a standalone function, use the 'object' keyword to declare a singleton object and make it a method of that.
—Jens
--
Viktor Klang
Senior Systems Analyst
object Foo {
def f(x:Int) = ...
}
Is that f is a top level function in the Foo module.
On Sat, Jan 31, 2009 at 8:41 PM, Russ Paielli <russ.paielli@gmail.com> wrote: