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: mi...@milessabin.com
skype: milessabin
http://www.chuusai.com/
http://twitter.com/milessabin
Paul
Seems like a different kind of module to what I'm thinking of. This looks like just a way to structure code.
I'm thinking of versioned deployable artifacts. Plus mechanisms like Ruby gems or I guess Maven/OSGi/Jigsaw in Java. A mechanism to declare the dependencies of code.
Bob
Thanks for the pointer. Do you mean the discussion in the "Related
Work" section of the "Mixin' up the ML Module System" paper?
Well, in OCaml, "versioned deployable artifacts" and "mechanisms to
declare the dependencies of code" can be done by using first-class
modules (not only a way to structure code, but also a runtime value
analog to a C struct). You'd dynamically load a module satisfying a
given module signature, and you'd pass the module around in your code as
a first-class runtime value. Some kind of "plugin".
This is not really a problem with ML-style modules, except that it
indeed was intended more as a way to structure code as opposed to any
kind of OSGi replacement.
Now, I do not see why you wouldn't be able to use the OSGi Java
machinery from Scala itself.
--
Guillaume Yziquel
Most Scala libraries use Maven or Ivy (which interoperate pretty well). Sbt provides particularly good support for Ivy. Is there anything that Maven/Ivy don't give you that you think would justify a Scala-specific solution?
--
paul.butcher->msgCount++
Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?
http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher
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
Its just a sense that classes/objects are too low level a unit to be thinking in terms of. And Maven/OSGi type solutions feel like tacking the extra data on after the fact rather than building it in the base unit you produce day-to-day. Why should packaging and deployment be something separate to development? Why not compile modules rather than classes?
All, thanks for the other links, which are useful.
Bob
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
If this was just asking for your own curiosity, then Scala will offer full support for Jigsaw once it's released with Java 8.
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?
That's the idea of modules. I do it all the time.
Paul
After reading I thought, that one can use a Scala object as container for an own library. But itseems that nobody does it in reality. Hmmm...