how to release a module in Haskell that can be used in another program? - haskell

I'm a beginner of Haskell, and I got a question here, how to release or build a module which can be used in another program ?
For example, when I use Java, I can write some classes, some functions and make it to be a jar that can be use in another program. So , how does this go with Haskell? Is there necessary to use the same functions, modules with the source code ?
And thanks.

If you're fine with sharing your library and its source code with everyone, it is common to upload it to Hackage. Other projects built with any common Haskell build tool know how to interface with Hackage packages
If you want to selectively share your library and its source code, you can upload it to a private or public github repository, and it could be used as a stack dependency
If you want to share the library locally with yourself, stack supports depending on local paths
If you wish to share your library without sharing source code, you can expose a C-api and make a DLL

Related

Set compiler for 1 package in Haskell Stack

I'm trying to write a small web application fully in Haskell. I have 3 logical packages:
A backend, using servant
A frontend, using reflex, reflex-dom and servant-reflex
A shared package defining the Servant API for communication between the 2 and some data types for that API to use.
That last package is giving me trouble. I don't know how to structure the project so the other 2 packages can use it. I see 2 options at the moment:
Each package has its own stack file and git repository. Import the shared package using an extra-deps git link. The problem with this approach is it means I have to push any change to the shared package to GitHub before I can test it out with the other packages. Also I'd have to build everything separately.
Use a single repository with a single stack.yml file. I'd prefer this, since it keeps everything together and also assures all packages are using the same resolver. In this case I would list all the packages in the packages: option. However, the client needs to be compiled with GHCJS, not GHC, and I don't see an option in the documentation to override the compiler for 1 specific package.
Is there a way to make option 2 work? Or is there a better way to do this?
The recommended approach is to have two stack project files (e.g. stack-frontend.yaml using GHCJS and stack-backend.yaml using GHC), and then use the --stack-yaml argument to switch between them (e.g. use stack --stack-yaml=stack-frontend.yaml build to build the frontend, and stack --stack-yaml=stack-backend.yaml build to build the backend). Both stack-*.yaml files can include the shared servant API.

How do I use stack to install locally authored Haskell modules for global usage?

I have a locally authored Haskell project, which produces both:
a binary executable, and
several new Haskell modules, which I'd like made accessible to my other, Haskell based, executables.
After:
stack build
stack install
I'm finding that:
the binary executable (#1, above) runs just fine from any directory.
But, the new Haskell modules (#2, above) are only found when I'm running from within my project directory! (That is, for any executable other than #1, above.)
I need to be able to find the new modules from anywhere.
How can I achieve this?
Each stack project is in its own sandbox, so the compiled modules can only be used within that project. Compiled dependencies (which come from a stackage snapshot) sometimes get shared between projects.
Note that you can list a relative path in the packages list, and point to this package. It will get built again, but it can be directly used in another project this way. Why the extra building? Stack has a different model of projects than cabal-install - it does not allow mutations to the package DB to affect how your other projects build.
One option for sharing such a package is to have it in a git repo and use https://docs.haskellstack.org/en/stable/custom_snapshot/ , but that stuff is still a bit new.

When using someone else's application code do I need to run Cmake to get the project structure for my operating system.

I am getting into a position where I have to use other people code for projects, for example openTLD. I want to change some of the code to give it more functionality and use it in a diffrent way. What I have found is that many people have packaged their files in such a way that you are supposed to use
cmake
and then
make
and sometimes after that
make install
I don't want to install the software on my system. What I am looking to do is get these peoples code to a point where I can add to it in Eclipse or even just using Nano and then compile it.
At what point is the code in a workable/usable state. Can I use it after doing cmake or do I need to also call make? Is my thinking correct that it would be better to edit the code after calling cmake as opposed to before? I am not going to want my finished code to be cross platform supported, it will only be on Linux. Is it easer to learn cmake and edit the code befor running cmake as opposed to not learning cmake and using the code afterwards, if that is possible?
You question is a little open ended.
Looking at the opentld project, there is a binary and a library available for use. If you are interested in using the binary in your code, you need to download the executables(Linux executables are not posted). If you are planning to use the library, you have two options. Either you use the pre-built library or build it during your build process. You would include the header files in your custom application and link with the library.
If you add more details, probably others can pitch in with new answers or refine the older ones.

How to partially use Android platform native code in my Java code

I need to call a function which belongs to a native Android code written in C . i just need one function and the native code is huge. What would be the way to achieve this in best possible way?
Do you mind to disclose the name of the function? I am asking because native non-documented APIs in Android can be crudely divided into three categories: code that is ODM dependent, code that is relatively stable, and code that is unstable or not exported by system libraries.
Regarding the first, you have no choice but to use the device-specific library. Usually, you can download such library from one device, and, not without great care, your library that dynamically links to that system lib, may work on other devices. Typical example is the OpenMAX family of libraries (see for example Creating Android app using OpenMAX library in GB, but showing not found?).
Regarding the second, the purists will download parts of the source tree and compile them into their local shared lib, but the practice of reusing a system lib is widespread (see for example shared memory in android ndk).
For the third, you have no choice but to recompile the AOSP code yourself.

Building Dynamic Library for a complex project using makefiles on Linux

I'm trying to build a shared library on Linux having different modules, and since source files are spreded in different sub directories, I am having trouble figuring out how to create scripts and makefiles to compile the whole project as a single Dynamic shared Library with modules depending on other modules.
Could anyone please give me any examples or tutorials to help me ?
I always found this article useful:
Static, Shared Dynamic and Loadable Linux Libraries
From there you'll want to do a tutorial on Make.

Resources