Running Haddock on its own - haskell

I would like to start using Haddock; the primary reason is not that I do (or anyone else does) need nice HTML documentation for what I'm writing right now, but that it will teach me a standardized way commenting Haskell modules.
For this reason, I'd like to get my hands dirty with it, but I've run into a pretty basic problem.
Source:
module Main where
-- |This is the main function.
main = putStrLn "Hello World!"
Haddock invocation:
> haddock -h test.hs
Haddock coverage:
50% ( 1 / 2) in 'Main'
Warning: Main: could not find link destinations for:
GHC.Types.IO
It looks like Haddock doesn't know where to look for the standard libraries, but that's just a wild guess. The docs say something about a "-B" parameter, but are not really explaining much about it.
I've searched for the problem online, and it was basically answered with "use a Cabal package and it'll do everything for you". However, I would much rather not deal with Cabal right now, but learn Haddock on its own (Cabal can wait). Is there a nice and easy(ish) solution to the problem?

I'm going to echo the wisdom of the comments to your question and say, just use Cabal. It's not an extra thing to learn, it's something to learn instead precisely because it takes care of all these tedious details for you. You'll probably need to know about it anyway since everyone else uses it, so you might as well get the benefit of that knowledge.
For completeness, I ran cabal haddock -v on one of my projects, and this is the invocation of haddock that it used:
/usr/local/bin/haddock --prologue=dist/doc/html/notcpp/haddock-prolog1566.txt --dump-interface=dist/doc/html/notcpp/notcpp.haddock --optghc=-package-name --optghc=notcpp-0.2.0.2 --hide=NotCPP.Utils --verbosity=1 --html --read-interface=/usr/local/share/doc/ghc/html/libraries/array-0.4.0.1,/usr/local/share/doc/ghc/html/libraries/array-0.4.0.1/array.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/base-4.6.0.0,/usr/local/share/doc/ghc/html/libraries/base-4.6.0.0/base.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/containers-0.5.0.0,/usr/local/share/doc/ghc/html/libraries/containers-0.5.0.0/containers.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/deepseq-1.3.0.1,/usr/local/share/doc/ghc/html/libraries/deepseq-1.3.0.1/deepseq.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/ghc-prim-0.3.0.0,/usr/local/share/doc/ghc/html/libraries/ghc-prim-0.3.0.0/ghc-prim.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/integer-gmp-0.5.0.0,/usr/local/share/doc/ghc/html/libraries/integer-gmp-0.5.0.0/integer-gmp.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/pretty-1.1.1.0,/usr/local/share/doc/ghc/html/libraries/pretty-1.1.1.0/pretty.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/template-haskell-2.8.0.0,/usr/local/share/doc/ghc/html/libraries/template-haskell-2.8.0.0/template-haskell.haddock --odir=dist/doc/html/notcpp/ --title=notcpp-0.2.0.2: Avoiding the C preprocessor via cunning use of Template Haskell --optghc=-fbuilding-cabal-package --optghc=-O --optghc=-odir --optghc=dist/build/tmp-1566 --optghc=-hidir --optghc=dist/build/tmp-1566 --optghc=-stubdir --optghc=dist/build/tmp-1566 --optghc=-i --optghc=-idist/build --optghc=-i. --optghc=-idist/build/autogen --optghc=-Idist/build/autogen --optghc=-Idist/build --optghc=-optP-include --optghc=-optPdist/build/autogen/cabal_macros.h --optghc=-hide-all-packages --optghc=-package-id --optghc=base-4.6.0.0-eac4fa0d0988628e5bd960fef8805b26 --optghc=-package-id --optghc=template-haskell-2.8.0.0-102a52a4fda28374255d0a3a8e99f26c --optghc=-XHaskell98 --optghc=-XTemplateHaskell --optghc=-W -B/usr/local/lib/ghc-7.6.1 dist/build/tmp-1566/NotCPP/ScopeLookup.hs dist/build/tmp-1566/NotCPP/LookupValueName.hs dist/build/tmp-1566/NotCPP/OrphanEvasion.hs dist/build/tmp-1566/NotCPP/Utils.hs
Now, I'm sure much of that is optional, but I'm not about to spend the time working out which bits are and which aren't.

Related

How to choose a specific msvcr.dl in Nim?

I would like to use an old msvcr71.dll when compiling Nim.
Is there a way to do so? If yes, how?
This is explained in the manual, right here. As StackOverflow doesn't like link responses, a copy-paste:
proc imported_proc(): ReturnType
{.cdecl, dynlib: "msvcr71.dll", importc.}
This asumes there is a function in msvcf71.dll called imported_proc that you want to wrap in your Nim code without changing the name.
You can also tweak which libraries to load when compiling, as explained here:
$ nim c --dynlibOverride:msvcr71 --passL:msvcr71.dll program.nim
Didn't test any of the code, hope it helps. You can always try to find some code that does this kind of linking, for example https://github.com/khchen/wNim/blob/master/wNim/private/winimx.nim or maybe https://github.com/brentp/hts-nim/blob/master/src/hts/private/hts_concat.nim

How to create haskell cabal package as output of haskell code?

The Haskell project I am working on generates code(and tests for it) that is intended to be used as an independent Haskell library. I want to wrap it in a cabal project, so it can be included as a dependency.
I searched for a library interface for the cabal, so I can create a cabal project at a given directory by calling some functions, but found none.
I could, of course, just run bash commands from Haskell, but it looks ugly to me.
Is there any tool that will solve my problem in a nice way?
You want the Cabal package. You can parse an existing cabal file, change stuff in the data structures, and regenerate the text representation.
Edit in answer to comment:
I don't know of any tutorials. The links I gave are for the Haddock docs, and the mapping between data types and Cabal file text is pretty straightforward. So you should probably start by writing the code to produce a PackageDescription value and then call writePackageDescription on it.
Note the existence of emptyPackageDescription, which lets you just specify the fields you want.
(Removed link to pretty printer class because PackageDescription isn't a member.)

Haskell skeleton template project for beginners

I have 3 data constructors say A,B and C that are defined in files A.hs, B.hs, C.hs and the files are in the directory project-utils.
Now I want to use these data constructors in parts of other projects. These projects reside in totally different directories.
How do I import the data and type constructors of A, B and C in such project files?
Thanks to the first answer given below, I realized that I am looking for a skeleton to organize such project in a better way. I searched but could not find any such project skeleton.
The link provided there contains many things that are described in vague manner. For example, on line 5 there it is simple written as "..."
What i am looking for is,
The skeleton project should not be very simple "single" file project as is given on the Haskell site. But should NOT be overly complex with tons of dependencies etc that we see in many projects on hackage.
Edit: I changed the title to reflect my problem in a better way. Sorry for the inconvenience.
Make a cabal pkg out of them and install that package locally.
Follow a directory stucture as here and use those constuctors in a project rather than across projects. The stucture mentioned is basically a structure of a cabal package.
Manually add the input source while compiling through ghc or loading in ghci.
Example
ghci -i project-utils/A.hs Foo.hs
where Foo.hs uses elements exported by A.hs
May not be exactly what you're looking for, but for future readers of this question, a Haskell skeleton/template project was just released here:
https://github.com/tfausak/haskeleton
It does add some dependencies like hlint and hspec. Here is the blog post, which goes through each of the individual decisions:
http://taylor.fausak.me/2014/03/04/haskeleton-a-haskell-project-skeleton/
I found this: how to write a haskell program link as a handy reference.
#Tem Pora : you need to install yesod and yesod-bin. This link talks more about the scaffolding
cabal install yesod
cabal install yesod-bin
<cdtoprojdir> yesod init
Hope this helps.

example of using external libraries or packages in Common Lisp

In Common Lisp, quicklisp is a popular library management tool. I'm going to use that tool and I'm going to try and use CL-WHO. I use the SBCL 1.0.57 implementation. I'm going to answer my own question below.
As a beginner, it's not clear how ASDF and quicklisp actually work together. And so it's not clear how to actually use packages or libraries that you've downloaded through quicklisp in an external source file. The quicklisp FAQ, at least at this moment, does not help. In python, it's incredibly simple: you can just put 'import somemodule' and life is great. Is there an equivalent for CL+quicklisp?
If you search, you find many results. Here are some of the most relevant ones I've found:
Lisp importing/loading file
How to use packages installed by quicklisp?
When I was reading through these originally, at least one question came to mind: do I actually have to care about ASDF if I'm using quicklisp? Quicklisp seems to be a higher level management tool. Other people suggest using quickproject. But is that really necessary?
The analogy to Python's imports is the system definition... well, this is a very loose analogy, but, it's the way to go. You declare dependencies in the system definition and then in source code you expect it to be there, so that if you later refer to the bits of the foreign code, you just do it.
Eg. in the system definition you might have: (usually it would be in my-program.asd file)
(defsystem :my-program
:version "0.0.1"
:serial t
:description "My program"
:components ((:file "some-source-file"))
;; `some-external-package' here is the "import", i.e. here you
;; declared that you will be using code from this package.
;; ASDF will generally "know" how to get the code of that package
;; from here on. But if it doesn't, then there are ways to "help it"
;; similar to how in Python there's a procedure to prepare your local
;; files to be used by easy_install
:depends-on (:some-external-package))
Later on in your code you just assume that the some-external-package is available to your program, e.g.:
(some-external-package:exported-symbol)
should just work. ("Your code" is the some-source-file.lisp, you've specified in the components).
This is the ASDF documentation on how to define systems
After you have this file in the place where ASDF might find it*, assuming you have ASDF installed (available to your Lisp, SBCL comes bundled with it), you'd load this system using (asdf:load-system :my-program) Explained here.
* - A quick way to test it would be to do
(push "/path/to/your/system/definition/" asdf:*central-registry*)
Download cl-who through the instructions on the quicklisp page and run this:
#!/usr/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
(ql:quickload "asdf")
(asdf:load-system 'cl-who)
(with-open-file (*standard-output* "out.html" :direction :output)
(cl-who:with-html-output (*standard-output* nil :indent t)
(:html
(:head
(:title "Test page"))
(:body
(:p "CL-WHO is really easy to use")))))
To the beginner, or someone who's really lazy, there's no reason why you should have to write 3 lines at the top instead of just one (like in python).

Real World Haskell code not compiling?

I'm trying to compile some code in Real World Haskell - Chapter 24. LineCount.hs.
I have not made any changes to the code.
However, when I do:
ghc -O2 --make -threaded LineCount.hs
(as instructed in the book), I get the message:
MapReduce.hs:6:7: Not in scope: `rnf'
What might I be doing wrong?
A quick search showed up that there was some trouble with the packages parallel and strict-concurrency in the past, and that reinstalling them would fix the issue. However, I tried that and it didn't work. Moreover, it is noted there that that issue was fixed sometime in 2010:
https://groups.google.com/forum/?fromgroups=#!msg/happs/gOieP4xfpNc/nrasm842JlUJ
Note: I get various other errors when compiling other files in the same chapter. For example, on compiling Strat.hs I get: Module Control.Parallel.Strategies' does not exportparZipWith'. On compiling LineChunks.hs I get: Module Control.Parallel.Strategies' does not exportrnf'.
Honestly, as a novice Haskell programmer I expected to run into trouble once I started modifying code - but I didn't expect to have trouble with code from a book!
The function is no longer called rnf. It's called rdeepseq now. Just replace it. :)
You can find the contents of the parallel package online by googling "control parallel strategies hackage", or clicking here.

Resources