1 %************************************************************************
3 \section[utils]{Other Haskell utility programs}
4 \index{utilities, Haskell}
6 %************************************************************************
8 This section describes other program(s) which we distribute, that help
9 with the Great Haskell Programming Task.
11 %************************************************************************
13 \subsection[mkdependHS]{Makefile dependencies in Haskell: using \tr{mkdependHS}}
15 \index{Makefile dependencies}
16 \index{dependencies in Makefiles}
18 %************************************************************************
20 It is reasonably straightforward to set up a \tr{Makefile} to use with
21 GHC, assuming you name your source files the same as your modules.
25 HCFLAGS = -recomp -cpp -hi-diffs $(EXTRA_HC_OPTS)
27 SRCS = Main.lhs Foo.lhs Bar.lhs
28 OBJS = Main.o Foo.o Bar.o
30 .SUFFIXES : .o .hi .lhs
35 $(HC) -c $< $(HCFLAGS)
39 $(HC) -o $@ $(HCFLAGS) $(OBJS)
42 Note the cheesy \tr{.o.hi} rule: It records the dependency of the
43 interface (\tr{.hi}) file on the source. The rule says a \tr{.hi}
44 file can be made from a \tr{.o} file by doing... nothing. Which is
47 (Sophisticated \tr{make} variants may achieve some of the above more
48 elegantly. What we've shown should work with any \tr{make}.)
50 The only thing lacking in the above \tr{Makefile} is interface-file
51 dependencies. If \tr{Foo.lhs} imports module \tr{Bar} and the
52 \tr{Bar} interface changes, then \tr{Foo.lhs} needs to be recompiled.
54 Putting dependencies of the form \tr{Foo.o : Bar.hi} into your
55 \tr{Makefile} by hand is rather error-prone. Don't worry---never
56 fear, \tr{mkdependHS} is here! (and is distributed as part of GHC)
57 Add the following to your \tr{Makefile}:
60 mkdependHS -- $(HCFLAGS) -- $(SRCS)
63 Now, before you start compiling, and any time you change the
64 \tr{imports} in your program, do \tr{make depend} before you do
65 \tr{make cool_pgm}. \tr{mkdependHS} will append the needed
66 dependencies to your \tr{Makefile}.
68 Please note the use of the recompilation checker (the \tr{-recomp}
69 \index{-recomp option} flag). Without it, your dependencies will be
70 {\em inadequate} to cope with the Haskell~1.3 module system! See
71 \sectionref{recomp} for more details about the recompilation checker!
73 A few caveats about this simple scheme: (a)~You may need to compile
74 some modules explicitly to create their interfaces in the first place
75 (e.g., \tr{make Bar.o} to create \tr{Bar.hi}). (b)~You may have to
76 type \tr{make} more than once for the dependencies to have full
77 effect. However, a \tr{make} run that does nothing {\em does} mean
78 ``everything's up-to-date.'' (c) This scheme will work with
79 mutually-recursive modules but, again, it may take multiple
80 iterations to ``settle.''
82 To see \tr{mkdependHS}'s command-line flags, give it a duff flag,
83 e.g., \tr{mkdependHS -help}.
85 %************************************************************************
87 \subsection[hstags]{Emacs `TAGS' for Haskell: \tr{hstags}}
89 \index{TAGS for Haskell}
91 %************************************************************************
93 NB: \tr{hstags} is temporarily dead at version~2.01. Sigh.
95 `Tags' is a facility for indexing the definitions of
96 programming-language things in a multi-file program, and then using
97 that index to jump around among these definitions.
99 Rather than scratch your head, saying ``Now where did we define
100 `foo'?'', you just do (in Emacs) \tr{M-. foo RET}, and You're There!
101 Some people go wild over this stuff...
103 GHC comes with a program \tr{hstags}, which build Emacs-able TAGS
104 files. The invocation syntax is:
106 hstags [GHC-options] file [files...]
109 The best thing is just to feed it your GHC command-line flags.
110 A good Makefile entry might be:
114 hstags $(GHC_FLAGS) *.lhs
117 The only flags of its own are: \tr{-v} to be verbose; \tr{-a} to
118 **APPEND** to the TAGS file, rather than write to it.
120 Shortcomings: (1)~Instance declarations don't get into the TAGS file
121 (but the definitions inside them do); as instances aren't named, this
122 is probably just as well. (2)~Data-constructor definitions don't get
123 in. Go for the corresponding type constructor instead.
125 (Actually, GHC also comes with \tr{etags} [for C], and \tr{perltags}
126 [for You Know What]. And---I cannot tell a lie---there is Denis
127 Howe's \tr{fptags} [for Haskell, etc.] in the \tr{ghc/CONTRIB}
130 %************************************************************************
132 \subsection[happy]{``Yacc for Haskell'': \tr{happy}}
134 \index{Yacc for Haskell}
135 \index{parser generator for Haskell}
137 %************************************************************************
139 Andy Gill and Simon Marlow have written a parser-generator for
140 Haskell, called \tr{happy}.\index{happy parser generator} \tr{Happy}
141 is to Haskell what \tr{Yacc} is to C.
143 You can get \tr{happy} by FTP from \tr{ftp.dcs.gla.ac.uk} in
144 \tr{pub/haskell/happy}, the file \tr{happy-0.8.tar.gz}.
146 \tr{Happy} is at its shining best when compiled by GHC.
148 %************************************************************************
150 \subsection[pphs]{Pretty-printing Haskell: \tr{pphs}}
152 \index{pretty-printing Haskell code}
154 %************************************************************************
156 Andrew Preece has written
157 \tr{pphs},\index{pphs}\index{pretty-printing Haskell}
158 a utility to pretty-print Haskell code in LaTeX documents.
159 Keywords in bolds, variables in italics---that sort of thing. It is
160 good at lining up program clauses and equals signs, things that are
161 very tiresome to do by hand.
163 The code is distributed with GHC in \tr{ghc/CONTRIB/pphs}.