I can run this code in Haskell
module Foo where
test = 1
module Bar where
test = 2
module Main where
import Foo
import Bar
main = print "test"
But PureScript compiler return an error
Conflicting imports for test from modules Bar and Foo
Is this a bug?
It is not a bug, but it will be changed.
https://github.com/purescript/purescript/issues/1497
Related
In verilog, Is there any difference between import package at compilation unit scope(1) and module header(2)?
1) at compilation unit scope
import mypkg::*;
module my_module(
port_declaration
...
2) at module header
module my_module
import mypkg::*;
(
port_declaration
...
There is no compile error for all above cases. I expected that, with 1) way, it might cause duplicated import warning or error when there was another file that import mypkg at its compilation unit scope, but there was not.
Any difference between them?
In verilog both will cause compilation errors, so no difference :-).
In System Verilog there is a difference in scoping.
The import pkg::* before module declaration will pull all definitions of the package int he global scope. It means that all modules defined in this file or in other files which follow your file on the command line will be aware of this import. For exacmple
import pkg::abc_t;
modle top;
abc_t a;
...
endmodule
module child;
abc_t b;
...
endmodule
Import inside a module will only pull the package content into this module scope:
modle top;
import pkg::abc_t;
abc_t a;
...
endmodule
module child;
abc_t b; << error, not visible, needs import first
...
endmodule
So far so good, but what if the module port uses the package? In the first case no problem:
import pkg::*;
module top(input abc_t abc);
But import in the global scope is usually a bad thing, which can cause issues in big projects. The solution is to use import in the module header.
module top
import pkg::*;
(input abc_t abc);
Now you have the package imported in the module scope and let port declarations see this import as well.
I'm trying to call a module several levels up from pytest run directory. How do I import this module?
I've tried:
sys.path.insert(0, 'path/to/module')
import modulename
Here's the directory structure:
tools
common
modulename.py (contains class A)
functional_test (this is where I'm running pytest; tools/functional_test)
conftest.py
pytest.ini
tests
typea (this is tools/funtional_tests/tests/typea)
tests_typea1.py
Under tests_typea1.py, I want to import class A from modulename.py under tools/common.
Getting the following Errors:
ImportError
ModuleNotFoundError: No module named 'modulename'
Well, after having another person look over my code, I realized that I miss-spelled my the import . Ugh... Note to self: change font style and confirm spelling. :). The above sys.path.insert or sys.path.append with import <modulename> works.
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.
I'm using:
% scalac -version
Scala compiler version 2.9.1 -- Copyright 2002-2011, LAMP/EPFL
on Ubuntu 12.04.
This code is saved in HelloGui.scala:
import scala.swing._
object HelloGui extends SimpleSwingApplication {
def top = new MainFrame {
title = "Hello World GUI"
contents = new Button {
text = "Click me"
}
}
}
When I try to compile this I get:
% scalac HelloGui.scala
HelloGui.scala:1: error: object swing is not a member of package scala
import scala.swing._
^
one error found
I've tried using import swing._ (it isn't clear from the tutorials which import path I need to use with this version of scala), and I get:
% scalac HelloGui.scala
HelloGui.scala:1: error: not found: object swing
import swing._
^
one error found
When I look in /usr/share/java, I see scala-swing-2.9.1.jar and scala-swing.jar as a symlink to it, so it seems like the libraries are present?
Am I missing a compiler flag or is there another package I need to install?
The compiler needs to have the path to the swing jar passed explicitly. This works:
% scalac -classpath /usr/share/java/scala-swing.jar HelloGui.scala
I am learning Scala so bear with me if this is a stupid question.
I have this package and a class (teared it down to most simplistic version):
package Foo {
class Bar {}
}
then in main.scala file I have:
import Foo.Bar
object test {
def main() {
val b = new Bar()
}
}
Why am I getting this:
test.scala:1: error: Bar is not a member of Foo
It points at the import statement.
scalac is the scala compiler. Foo.bar needs to have been compiled for you to use it, so you can't just run your main.scala as a script.
The other mistake in your code is that the main method needs to be
def main(args: Array[String]) { ...
(or you could have test extends App instead and do away with the main method).
I can confirm if you put the two files above in an empty directory (with the correction on the main method signature) and run scalac * followed by scala test it runs correctly.
The most likely explanation is that you did not compile the first file, or you are doing something wrong when compiling. Let's say both files are in the current directory, then this should work:
scalac *.scala
It should generate some class files in the current directory, as well as a Bar.class file in the Foo directory, which it will create.
To quickly test a scala code in IntelliJ (with the Scala plugin), you can simply type Ctrl+Shift+F10:
Note that for testing a Scala class, you have other choices, also supported in IntelliJ:
JUnit or TestNG
ScalaTest