This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Modules?

14 replies
BobLondon
Joined: 2011-11-03,
User offline. Last seen 42 years 45 weeks ago.

I've been taking a look at Scala and liking some but not all of what I
see. However, I was surprised to see Scala as a "scalable language"
but without any obvious support for modules in the language. Am I
missing something? Why would you create a new language without support
for modules?

Bob

Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?

On 03/11/11 20:54, BobLondon wrote:
> I've been taking a look at Scala and liking some but not all of what I
> see. However, I was surprised to see Scala as a "scalable language"
> but without any obvious support for modules in the language. Am I
> missing something? Why would you create a new language without support
> for modules?
>
> Bob
Scala has modules. See the object keyword.

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Modules?

On Thu, Nov 3, 2011 at 10:54 AM, BobLondon wrote:
> I've been taking a look at Scala and liking some but not all of what I
> see. However, I was surprised to see Scala as a "scalable language"
> but without any obvious support for modules in the language. Am I
> missing something? Why would you create a new language without support
> for modules?

Scala objects and path dependent types encode ML-style modules,

trait Signature {
type T
def succ(t : T) : T
def zero : T
}

object IntStructure extends Signature {
type T = Int
def succ(t : T) = t+1
def zero = 0
}

object StringStructure extends Signature {
type T = String
def succ(t : T) = t+"*"
def zero = ""
}

Sample REPL session,

scala> import StringStructure._
import StringStructure._

scala> val z = zero
z: java.lang.String = ""

scala> val one = succ(z)
one: java.lang.String = *

Cheers,

Miles

Paul Brauner
Joined: 2010-10-28,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?

To be precise, Scala goes beyond ML modules by providing first class
ML modules (as in Moscow ML and OCaml). It also has (to some extent)
first class functors.

Paul

On Thu, Nov 3, 2011 at 12:06, Miles Sabin wrote:
> On Thu, Nov 3, 2011 at 10:54 AM, BobLondon wrote:
>> I've been taking a look at Scala and liking some but not all of what I
>> see. However, I was surprised to see Scala as a "scalable language"
>> but without any obvious support for modules in the language. Am I
>> missing something? Why would you create a new language without support
>> for modules?
>
> Scala objects and path dependent types encode ML-style modules,
>
>  trait Signature {
>    type T
>    def succ(t : T) : T
>    def zero : T
>  }
>
>  object IntStructure extends Signature {
>    type T = Int
>    def succ(t : T) = t+1
>    def zero = 0
>  }
>
>  object StringStructure extends Signature {
>    type T = String
>    def succ(t : T) = t+"*"
>    def zero = ""
>  }
>
> Sample REPL session,
>
>  scala> import StringStructure._
>  import StringStructure._
>
>  scala>   val z = zero
>  z: java.lang.String = ""
>
>  scala>   val one = succ(z)
>  one: java.lang.String = *
>
> Cheers,
>
>
> Miles
>
> --
> Miles Sabin
> tel: +44 7813 944 528
> gtalk: miles [at] milessabin [dot] com
> skype: milessabin
> http://www.chuusai.com/
> http://twitter.com/milessabin
>

Paul Brauner
Joined: 2010-10-28,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?

Also see http://www.mpi-sws.org/~rossberg/ for a comparison between
scala's objects and ML modules.

On Thu, Nov 3, 2011 at 11:55, Tony Morris wrote:
> On 03/11/11 20:54, BobLondon wrote:
>> I've been taking a look at Scala and liking some but not all of what I
>> see. However, I was surprised to see Scala as a "scalable language"
>> but without any obvious support for modules in the language. Am I
>> missing something? Why would you create a new language without support
>> for modules?
>>
>> Bob
> Scala has modules. See the object keyword.
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Modules?

On Thu, Nov 3, 2011 at 11:08 AM, Paul Brauner wrote:
> Also see http://www.mpi-sws.org/~rossberg/ for a comparison between
> scala's objects and ML modules.

Thanks for the pointer. Do you mean the discussion in the "Related
Work" section of the "Mixin' up the ML Module System" paper?

Cheers,

Miles

Paul Brauner
Joined: 2010-10-28,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?

On Thu, Nov 3, 2011 at 12:33, Miles Sabin wrote:
> On Thu, Nov 3, 2011 at 11:08 AM, Paul Brauner wrote:
>> Also see http://www.mpi-sws.org/~rossberg/ for a comparison between
>> scala's objects and ML modules.
>
> Thanks for the pointer. Do you mean the discussion in the "Related
> Work" section of the "Mixin' up the ML Module System" paper?

Yes. It's not much but I think it's up to date (the paper is very
recent and I know from Andreas that he updated it to take Scala's last
developments into account).

Paul

Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: Modules?
For build-time management of "modules", Maven artefacts are the de-facto Java standard.  You don't have to use Maven as a build tool though, Ant, SBY, Ivy, and others are all capable of working with Maven repositories.
If you want want to manage, load, unload, etc. versioned and encapsulated units of functionality *at run time* then it's really a platform problem, not a language one.  Scala isn't responsible for isolating classloaders and loading bytecode, the Java platform is.
Having said that, Java does have a solution - in the form of OSGi.  We also have a rather nice wrapper/DSL around OSGi provided via the scalamodules project [1]
Somewhere in the middle is the Jigsaw project.  Jigsaw is much less intrusive that OSGi, and is intended to work at both build and run time.  You can expect to see a 1-to-1 correspondance between Jigsaw modules and OS-native equivalents (such as deb packages in Ubuntu).  You'll also see the Java standard library being carved up by Jigsaw, and offering a much smaller initial footprint.
If you need something now, and it absolutely has to be at runtime with dynamic loading/unloading, then use OSGi+scalamodules.  If this was just asking for your own curiosity, then Scala will offer full support for Jigsaw once it's released with Java 8.  Even if we don't get a nice Scala wrapper in the core library, you can be quite sure that *someone* will be keen to do this as a 3rd party offering.
[1] https://github.com/weiglewilczek/scalamodules

On 3 November 2011 11:44, Paul Brauner <polux2001 [at] gmail [dot] com> wrote:
On Thu, Nov 3, 2011 at 12:33, Miles Sabin <miles [at] milessabin [dot] com> wrote:
> On Thu, Nov 3, 2011 at 11:08 AM, Paul Brauner <polux2001 [at] gmail [dot] com> wrote:
>> Also see http://www.mpi-sws.org/~rossberg/ for a comparison between
>> scala's objects and ML modules.
>
> Thanks for the pointer. Do you mean the discussion in the "Related
> Work" section of the "Mixin' up the ML Module System" paper?

Yes. It's not much but I think it's up to date (the paper is very
recent and I know from Andreas that he updated it to take Scala's last
developments into account).

Paul



Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?
Also there's https://github.com/marcusatbang/Hooks --- anyone have opinions on it?

On Thu, Nov 3, 2011 at 8:32 AM, Kevin Wright <kev [dot] lee [dot] wright [at] gmail [dot] com> wrote:
For build-time management of "modules", Maven artefacts are the de-facto Java standard.  You don't have to use Maven as a build tool though, Ant, SBY, Ivy, and others are all capable of working with Maven repositories.
If you want want to manage, load, unload, etc. versioned and encapsulated units of functionality *at run time* then it's really a platform problem, not a language one.  Scala isn't responsible for isolating classloaders and loading bytecode, the Java platform is.
Having said that, Java does have a solution - in the form of OSGi.  We also have a rather nice wrapper/DSL around OSGi provided via the scalamodules project [1]
Somewhere in the middle is the Jigsaw project.  Jigsaw is much less intrusive that OSGi, and is intended to work at both build and run time.  You can expect to see a 1-to-1 correspondance between Jigsaw modules and OS-native equivalents (such as deb packages in Ubuntu).  You'll also see the Java standard library being carved up by Jigsaw, and offering a much smaller initial footprint.
If you need something now, and it absolutely has to be at runtime with dynamic loading/unloading, then use OSGi+scalamodules.  If this was just asking for your own curiosity, then Scala will offer full support for Jigsaw once it's released with Java 8.  Even if we don't get a nice Scala wrapper in the core library, you can be quite sure that *someone* will be keen to do this as a 3rd party offering.
[1] https://github.com/weiglewilczek/scalamodules

On 3 November 2011 11:44, Paul Brauner <polux2001 [at] gmail [dot] com> wrote:
On Thu, Nov 3, 2011 at 12:33, Miles Sabin <miles [at] milessabin [dot] com> wrote:
> On Thu, Nov 3, 2011 at 11:08 AM, Paul Brauner <polux2001 [at] gmail [dot] com> wrote:
>> Also see http://www.mpi-sws.org/~rossberg/ for a comparison between
>> scala's objects and ML modules.
>
> Thanks for the pointer. Do you mean the discussion in the "Related
> Work" section of the "Mixin' up the ML Module System" paper?

Yes. It's not much but I think it's up to date (the paper is very
recent and I know from Andreas that he updated it to take Scala's last
developments into account).

Paul




E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?

On 2011-11-03 11:55, Tony Morris wrote:
> Scala has modules. See the object keyword.

There is some info in the Chapter 29 "Modular Programming Using Objects" in "Programming in Scala",
2nd ed. (for the 1st ed. also available online
http://www.artima.com/pins1ed/modular-programming-using-objects.html).

After reading I thought, that one can use a Scala object as container for an own library. But it
seems that nobody does it in reality. Hmmm...

It would be great to see some real-world usages of objects as modules in Scala.
Perhaps in std. library? In other projects?

Thanks!

--
Eugen

Simon Ochsenreither
Joined: 2011-07-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?


If this was just asking for your own curiosity, then Scala will offer full support for Jigsaw once it's released with Java 8.

How do you know that?
Paul Brauner
Joined: 2010-10-28,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?

> After reading I thought, that one can use a Scala object as container for an own library.

That's the idea of modules. I do it all the time.

Paul

Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: Modules?


On 4 November 2011 17:17, Simon Ochsenreither <simon [dot] ochsenreither [at] googlemail [dot] com> wrote:


If this was just asking for your own curiosity, then Scala will offer full support for Jigsaw once it's released with Java 8.

How do you know that?


Because it'll be a Java API, and I'm not aware of any Java feature that current versions of Scala can't use.  There are some features that Scala can't implement, but that's not the same thing at all.
Simon Ochsenreither
Joined: 2011-07-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?
Maybe I'm wrong, but the last proposal I saw was closely bundled with Java-the-language....
Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Modules?


On Fri, Nov 4, 2011 at 6:54 AM, Eugen Labun <labun [at] gmx [dot] net> wrote:
After reading I thought, that one can use a Scala object as container for an own library. But it seems that nobody does it in reality. Hmmm...

 Well, you use packages, which are similar to objects in Scala.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland