Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the canonical way to share modules between projects?

Tags:

haskell

Suppose there are three projects A, B and C. The modules in C will be shared by A and B. Because there is no java's CLASSPATH thing, then do we need to use absolute path when importing modules from C ?

Any suggestion is appreciated !

like image 518
z_axis Avatar asked Dec 05 '12 07:12

z_axis


People also ask

How do you share global variables across modules?

The best way to share global variables across modules across a single program is to create a config module. Just import the config module in all modules of your application; the module then becomes available as a global name.

How do I share code between projects in Python?

Setup.py allows you to create a custom Python package enabling you to share code easily within a project. Simply structure your sub-projects and shared code into folders containing an __init__.py and direct your setup.py 's setup() to install the code contained within shared code folder.

What is __ all __ in Python?

In the __init__.py file of a package __all__ is a list of strings with the names of public modules or other objects. Those features are available to wildcard imports. As with modules, __all__ customizes the * when wildcard-importing from the package.

Is it good practice to use global variables in Python?

While in many or most other programming languages variables are treated as global if not declared otherwise, Python deals with variables the other way around. They are local, if not otherwise declared. The driving reason behind this approach is that global variables are generally bad practice and should be avoided.


3 Answers

I urge you to cabalise your projects.

But if for some reason you don't want to do this, then the nearest thing to the java classpath is the -i switch to ghc. Note that the current directory needs to appear explicitly in the list.

like image 134
dave4420 Avatar answered Oct 21 '22 03:10

dave4420


The canonical way is to choose carefully where they should sit in the module hierarchy and make each project into a fully featured Cabal package, then install them locally so that they're a part of the namespace for your compiler locally.

This way the modules of each are available to any source code you're writing.

If (for example) you use the leksah IDE it'll do a lot of the work for you.

like image 42
AndrewC Avatar answered Oct 21 '22 04:10

AndrewC


If by "projects" you mean Cabal packages, the standard thing to do would be to export whatever modules are necessary from C and then have A and B depend on the C and import them. It's not a good idea to have source files in a package directly depend on files that are aren't part of that package.

like image 24
shachaf Avatar answered Oct 21 '22 05:10

shachaf