- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
top-level functions in a package
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










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
Re: top-level functions in a package
On Sun, Feb 1, 2009 at 6:04 AM, Jens Alfke <jens [at] mooseyard [dot] com> wrote:
--
Viktor Klang
Senior Systems Analyst
Re: top-level functions in a package
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 [dot] paielli [at] gmail [dot] com> wrote: