- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Modules?
Thu, 2011-11-03, 11:54
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
Thu, 2011-11-03, 12:17
#2
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
Thu, 2011-11-03, 12:17
#3
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
>
Thu, 2011-11-03, 12:27
#4
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/
>
>
>
Thu, 2011-11-03, 12:47
#5
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
Thu, 2011-11-03, 12:47
#6
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
Thu, 2011-11-03, 13:37
#7
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:
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
Fri, 2011-11-04, 01:57
#8
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:
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
Fri, 2011-11-04, 11:57
#9
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
Fri, 2011-11-04, 18:27
#10
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?
Fri, 2011-11-04, 18:27
#11
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
Fri, 2011-11-04, 18:37
#12
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.
Fri, 2011-11-04, 20:17
#13
Re: Modules?
Maybe I'm wrong, but the last proposal I saw was closely bundled with Java-the-language....
Mon, 2011-11-07, 02:37
#14
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.









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.