Expose a package object's declarations to subpackages in Scala - scala

I have the following packages hierarchy:
rootpackage
---firstpackage
---secondpackage
rootpackage contains a package object.
I know that if a file from firstpackage has package declaration in the form:
package rootpackage.firstpackage
the content of rootpackage package object will not be in the file scope, but with the following declaration it will:
package rootpackage
package firstpackage
How this strange difference is explained? And is there more transparent way to expose the package object's content to subpackages, like importing rootpackage package object content to firstpackage one?

Package object members can be imported in the following way:
import rootpackage.SomeMember

Related

Importing a local swift module

Swift newbie here, using swift 3 on Linux with the package manager.
I have a package Regulate, executable, and a sibling package Utils, intended to be a library. Utils/Sources has a TextReader.swift file, with class TextReader and its init function both public. The Utils directory is a git repo, described in Regulate/Package.swift:
dependencies: [.Package(url: "../Utils", "1.0.0")]
I've tried 3 ways to instantiate a TextReader object in the Regulate program and gotten 3 error messages:
import Utils
...
let reader = TextReader(filename: name)
error: use of unresolved identifier 'TextReader'
import Utils
...
let reader = Utils.TextReader(filename: name)
error: module 'Utils' has no member named 'TextReader'
import class Utils.TextReader
error: no such decl in module
It looks like the library module needs some additional structure to declare its exports, perhaps.
What do I need to do here? Thanks!
D'oh! This looks like a name conflict.
When I use Utils2 instead of Utils, it works fine. With Utils it cloned and built the other module, but apparently went to some system module instead when I referenced it.

Import declarations in a namespace from external module

I would like use TypeScript.NET in my angular application. I am newbie in typescript and maybe root of problem is simple.
For example I would like to use StringBuilder.
First I install TypeScript via nuget
Add ref to index.html
<script src="source/System/Text/StringBuilder.js"></script>
<script src="source/System/Text/Utility.js"></script>
Here I am confuse, I don’t use any module system (e.g commonJs, amd, etc).
TypeScript.NET nuget add to my project folder dist which constains probably dist version for amd, commonjs etc hence I reference files from source folder.
Now I want to use StringBuilder in my internal module.
module App.Company{
//in internal module
import IVersion = App.IVersion;
import IError = App.IError;
//TypeScript.NET
import StringBuilder from "../../../../source/system/text/stringbuilder";
}
Here I get compilation errror
Import declarations in a namespace cannot reference a module
What is solution?
Second how can simple reference all types from TypeScript.NET?

Add a scala file into parent package

I am in this situation:
The package "vu.co.kaiyin.clipboard" has been created and has a package object in it. Now I want to add a new scala file in the package "vu.co.kaiyin". How can I do that?
Do it on scala folder. Just add vu.co.kaiyin.new_package there - putting all path.

Scala: Importing packages into package objects

I'm having trouble importing packages into package objects. It didn't seem to work in Eclipse and so I switched to intellij. At one point the feature seemed to be working and so I created package objects for most packages. Now it doesn't seem to be working at all. Here's a package object in file package.scala, the package file itself compiles fine:
package rStrat.rSwing
package testSw //Edited for clarity
object testSw
{
import rStrat._
import rSwing.topUI._
}
and here's a class file from the same module and package.
package rStrat.rSwing.testSw
object MainTest {
def main(args: Array[String])
{
val testApp = new AppWindow //Appwindow is a member of topUI
testApp.open
}
}
It works fine if I import the topUI package straight into the MainTest file. it makes no difference whether I try and import the whole package or a particular class. is this legal scala? Is the problem with the IDEs?
I'm using Scala 2.92 Final, Intellij 11.1.1, JDK 1.6.0_31, Eclipse 3.7.2
Scala does not have first class imports. Where a package can only contain declarations of classes and traits, a package object can contain any other valid Scala declaration like var, val, def, type (type alias), implicit stuff. And although as in any object you can import things, they don't transitively propagate to the rest of the package and are thus not visible to the rest of the world.
This creates the object rStrat.rSwing.testSw.testSw:
package rStrat.rSwing
package testSw //Edited for clarity
object testSw
This creates the package object rStrat.rSwing.testSw.testSw:
package rStrat.rSwing
package testSw //Edited for clarity
package object testSw
This creates the package object rStrat.rSwing.testSw:
package rStrat.rSwing
package object testSw
It's the last one you want.

scala package conflict

I have a library which has root package "scala", and now I have a project using this library, and I have a sub package named "com.zjffdu.scala". And the class file in this package needs to import classes from the library. So I have the following import statement.
import scala._
But because this class is also in package "scala", the scala compiler will look for files in current directory rather than the library.
So how can I explicit to tell scala to import classes from the library.
Thanks
Use this:
import _root_.scala._
As you can see it's not very pretty — the best option is probably to avoid naming one of your packages scala.
And by the way — the root scala package is always preimported (though subpackages, of course, are not).