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.
Asked
Active
Viewed 167 times
4
-
See: [creating a Haskell DLL](https://downloads.haskell.org/~ghc/7.6.1/docs/html/users_guide/win32-dlls.html). – AJF Dec 24 '18 at 10:29
-
Is that means Haskell DLL equivalent to jar in Java? – Jacky Wong Dec 24 '18 at 10:31
-
4If you can release the source code, you probably should create a Cabal package, so that others can compile & install it by running `cabal install`. https://www.haskell.org/cabal/users-guide/intro.html – chi Dec 24 '18 at 10:39
-
I don't think there's a JAR equivalent for Haskell. JARs include enough information to allow one to compile against them. A DLL (or .so file) as far as I know only contains information to allow (dynamic) linking and running the library, but does not allow compilation. For compiling one also needs a bunch of `.hi` files (one per module), I believe. – chi Dec 24 '18 at 10:46
-
Thanks chi, so you mean if I sort out my program's `.cabal` file and pack it, send it to another program, it can be installed and be used ? – Jacky Wong Dec 24 '18 at 10:54
-
You don't need to “send it” to another program, you can just either `cabal install` it locally, or publish it on hackage so Cabal can automatically pull it as a dependency and anybody who may need the module has it available. – leftaroundabout Dec 24 '18 at 12:53
-
Possible duplicate of [Depending on a local package in cabal](https://stackoverflow.com/questions/19622809/depending-on-a-local-package-in-cabal) – jberryman Dec 24 '18 at 17:55
-
@jberryman Yes, I think so. If you send a "cabalized" source archive to someone, they can unpack it, and use cabal to compile and install it. – chi Dec 24 '18 at 22:39
-
4For the sake of completeness, I think I should add that the usual way to make your library available to other people is to upload it to [Hackage](https://hackage.haskell.org/); other people can then add your package as a dependency using Cabal. The package manager will then download the package and build it, allowing its modules to be used in your program. (Edit: formatting) – bradrn Dec 25 '18 at 00:41
-
1Oh thanks, I may know now. I write some tools , pack it, I can upload it to Hackage to make it possible to be downloaded and installed. Also, I can make another program depend on it. Am I right ? – Jacky Wong Dec 25 '18 at 08:17
-
Yes, that's right. Before uploading to Hackage, you can test it locally on your computer. You install the library with cabal, and then write another program exploiting the installed library. – chi Dec 25 '18 at 09:37
1 Answers
0
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

yairchu
- 23,680
- 7
- 69
- 109