How to load example in Djinn/UU/Examples/Equality.hs? - haskell

After cabal install Djinn which is using QuickCheck, the executable file is in ./.cabal/bin/djinn.
then I copy the executable to the directory Downloads/Djinn/UU/Examples/
want to run example Equality.hs then djinn Equality.hs, can not parse command
then ./djinn then :load full path/UU/Examples/Equality.hs
return cannot parse command

As the comment says, this doesn't make much sense. Djinn doesn't work on Haskell source files as far as I know. Also Djinn doesn't appear to use quickcheck.

Related

How can I run GHCi against a compiled package?

I should really know this by now, but I don't. I'm often working on a Cabal-based package and have just run a successful cabal build. Now I want to try some things out in GHCi. If I run cabal repl, then GHC recompiles the whole package into bytecode and runs it in the interpreter. Not what I want at all! If I were just running GHCi directly, I'd use something like -O -fobject-code, but that won't give me the package context. I just want "Give me a repl with the package as it's been compiled, compiling additional things only as necessary." How do I do it?
I don't know the right way, but I do know a workaround that can sometimes be useful. If the thing you care about is a library component, you can ask for a repl for an executable component.
I believe --repl-options -fobject-code kind of does what you want:
cabal repl --repl-options -fobject-code --repl-options -O --builddir dist-repl
This will give you incremental building of compiled code as you work in GHCi. Caveats:
dist-repl is an alternative directory for the -fobject-code build objects. As of cabal 3.6.2.0 at least, trying to reuse the regular output from cabal build leads to some unnecessary rebuilds and other strange behaviour, as reported at cabal issue #3565. That being so, it's better to compromise and use --builddir to keep a separate set of build objects. Note that cabal clean accepts the --builddir option just fine.
Setting the optimisation level explicitly is necessary, as otherwise the default -O0 from cabal repl will override your package setting.

Compiling simple programs on Haskell on Windows using the command line

This is a follow-up to this question, which is about whether it is possible to compile simple programs on Haskell in Windows, without recourse to Cygwin: Compiling Haskell programs in Windows: is it possible without downloading something such as Cygwin?
For background, I asked this question, since if there were some other way of compiling the program it would be very useful to know, since I am on a university computer and cannot download things like Cygwin without permission. (and even with permission it might not be possible, depending on what Cygwin requires)
Someone responded to my question, suggesting I open the command line and put ghc --make helloworld and hit Enter. However, when I put in ghc --make helloworld and hit Enter this comes up:
ghc: unrecognised flag: --
did you mean one of:
-D
-F
-H
Usage: For basic infomration, try the '--help' option
The person answering the question suggested I made another question, asking why I received the above message. How can I deal with this problem?
Yes, it is possible to use Windows to compile Haskell programs. In fact, I use Windows for all my Haskell programming! To compile a Haskell program, use ghc --make <program>; for instance, here it would be ghc --make helloworld.hs. Note that there is no space between -- and make; including this space gives the error you describe. After running this command, an executable helloworld.exe file is produced.

Is it possible to package c code with Haskell using cabal?

I have a c library that I'd like to provide an FFI interface for. This is easy enough, but I can't figure out how to get the packaging right. It would be nice to just be able to
cabal install librarybindings
and have cabal automatically build it with gcc, generate the .o file, and include that with the distribution. Right now, I can the package to compile fine, but when you go to build an executable using the bindings you have to explicitly pass ghc the .o file on the command line. Yuck.
Yes, you can ship C code with Haskell. See e.g.
bytestring
zlib
download
By convention the C bits are put in a cbits/ directory.

How to stop GHC from generating intermediate files?

When compiling a haskell source file via ghc --make foo.hs GHC always leaves behind a variety of intermediate files other than foo.exe. These are foo.hi and foo.o.
I often end up having to delete the .hi and .o files to avoid cluttering up the folders.
Is there a command line option for GHC not to leave behind its intermediate files? (When asked on #haskell, the best answer I got was ghc --make foo.hs && rm foo.hi foo.o.
I've gone through the GHC docs a bit, and there doesn't seem to be a built-in way to remove the temporary files automatically -- after all, GHC needs those intermediate files to build the final executable, and their presence speeds up overall compilation when GHC knows it doesn't have to recompile a module.
However, you might find that setting the -outputdir option will help you out; that will place all of your object files (.o), interface files (.hi), and FFI stub files in the specified directory. It's still "clutter," but at least it's not in your working directory anymore.
GHC now has the options no-keep-hi-files and no-keep-o-files. See here for more information.
My usual workflow is to use cabal rather than ghc directly. This sets the outputdir option into an appropriate build folder and can do things like build haddock documentation for you. All you need is to define the .cabal file for your project and then say cabal install or cabal build instead of run ghc directly. Since you need to follow this process in the end if you ever want to share your work on hackage, it is a good practice to get into and it helps manage package dependencies as well.
You can set the -hidir to /dev/null, I think, sending them there. Also, the -fno-code option in general turns off a lot of output. You might just want to use Cabal.
Turns out that using -hidir/-odir/-outputdir is no good; /dev/null is a file, and not a directory. See http://www.haskell.org/pipermail/xmonad/2010-May/010182.html
2 cents to improve the workflow a bit:
We can put the following alias into the .bashrc (or similar) config
file:
alias hsc='_hsc(){ ghc -no-keep-hi-files -no-keep-o-files "$#";}; _hsc'
And then just call
$ hsc compose.hs
[1 of 1] Compiling Main ( compose.hs, compose.o )
Linking compose ...
$ ls
compose compose.hs

Haskell cabal+hsc2hs

Can cabal use hsc2hs to create hs files? How?
I didn't find an answer in the manuals, googling, nor in other projects (had my hopes up for gtk2hs but it turns out that it doesn't use cabal)
Yes, cabal understands that when you list module Foo in your .cabal file, and it finds Foo.hsc on disk, that it must run hsc2hs on the module first.
Cabal transparently handles the existence of .hsc files.

Resources