[project @ 1996-06-27 15:55:53 by partain]
[ghc-hetmet.git] / ghc / docs / users_guide / utils.lit
1 %************************************************************************
2 %*                                                                      *
3 \section[utils]{Other Haskell utility programs}
4 \index{utilities, Haskell}
5 %*                                                                      *
6 %************************************************************************
7
8 This section describes other program(s) which we distribute, that help
9 with the Great Haskell Programming Task.
10
11 %************************************************************************
12 %*                                                                      *
13 \subsection[mkdependHS]{Makefile dependencies in Haskell: using \tr{mkdependHS}}
14 \index{mkdependHS}
15 \index{Makefile dependencies}
16 \index{dependencies in Makefiles}
17 %*                                                                      *
18 %************************************************************************
19
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.
22 Thus:
23 \begin{verbatim}
24 HC      = ghc
25 HCFLAGS = -fhaskell-1.3 -cpp -hi-diffs $(EXTRA_HC_OPTS)
26
27 SRCS = Main.lhs Foo.lhs Bar.lhs
28 OBJS = Main.o   Foo.o   Bar.o
29
30 .SUFFIXES : .o .hi .lhs
31 .o.hi:
32         @:
33 .lhs.o:
34         $(RM) $@
35         $(HC) -c $< $(HCFLAGS)
36
37 cool_pgm : $(OBJS)
38         $(RM) $@
39         $(HC) -o $@ $(HCFLAGS) $(OBJS)
40 \end{verbatim}
41
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
45 true.
46
47 (Sophisticated \tr{make} variants may achieve some of the above more
48 elegantly.  What we've shown should work with any \tr{make}.)
49
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.
53
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}:
58 \begin{verbatim}
59 depend :
60         mkdependHS -- $(HCFLAGS) -- $(SRCS)
61 \end{verbatim}
62
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}.
67
68 A few caveats about this simple scheme: (a)~You may need to compile
69 some modules explicitly to create their interfaces in the first place
70 (e.g., \tr{make Bar.o} to create \tr{Bar.hi}).  (b)~You may have to
71 type \tr{make} more than once for the dependencies to have full
72 effect.  However, a \tr{make} run that does nothing {\em does} mean
73 ``everything's up-to-date.''  (c) This scheme will work with
74 mutually-recursive modules but, again, it may take multiple
75 iterations to ``settle.''
76
77 To see \tr{mkdependHS}'s command-line flags, give it a duff flag,
78 e.g., \tr{mkdependHS -help}.
79
80 %************************************************************************
81 %*                                                                      *
82 \subsection[hstags]{Emacs `TAGS' for Haskell: \tr{hstags}}
83 \index{hstags}
84 \index{TAGS for Haskell}
85 %*                                                                      *
86 %************************************************************************
87
88 `Tags' is a facility for indexing the definitions of
89 programming-language things in a multi-file program, and then using
90 that index to jump around among these definitions.
91
92 Rather than scratch your head, saying ``Now where did we define
93 `foo'?'', you just do (in Emacs) \tr{M-. foo RET}, and You're There!
94 Some people go wild over this stuff...
95
96 GHC comes with a program \tr{hstags}, which build Emacs-able TAGS
97 files.  The invocation syntax is:
98 \begin{verbatim}
99 hstags [GHC-options] file [files...]
100 \end{verbatim}
101
102 The best thing is just to feed it your GHC command-line flags.
103 A good Makefile entry might be:
104 \begin{verbatim}
105 tags:
106         $(RM) TAGS
107         hstags $(GHC_FLAGS) *.lhs
108 \end{verbatim}
109
110 The only flags of its own are: \tr{-v} to be verbose; \tr{-a} to
111 **APPEND** to the TAGS file, rather than write to it.
112
113 Shortcomings: (1)~Instance declarations don't get into the TAGS file
114 (but the definitions inside them do); as instances aren't named, this
115 is probably just as well.  (2)~Data-constructor definitions don't get
116 in.  Go for the corresponding type constructor instead.
117
118 (Actually, GHC also comes with \tr{etags} [for C], and \tr{perltags}
119 [for You Know What].  And---I cannot tell a lie---there is Denis
120 Howe's \tr{fptags} [for Haskell, etc.] in the \tr{ghc/CONTRIB}
121 section...)
122
123 %************************************************************************
124 %*                                                                      *
125 \subsection[happy]{``Yacc for Haskell'': \tr{happy}}
126 \index{happy}
127 \index{Yacc for Haskell}
128 \index{parser generator for Haskell}
129 %*                                                                      *
130 %************************************************************************
131
132 Andy Gill and Simon Marlow have written a parser-generator for
133 Haskell, called \tr{happy}.\index{happy parser generator} \tr{Happy}
134 is to Haskell what \tr{Yacc} is to C.
135
136 You can get \tr{happy} by FTP from \tr{ftp.dcs.glasgow.ac.uk} in
137 \tr{pub/haskell/happy}, the file \tr{happy-0.8.tar.gz}.
138
139 \tr{Happy} is at its shining best when compiled by GHC.
140
141 %************************************************************************
142 %*                                                                      *
143 \subsection[pphs]{Pretty-printing Haskell: \tr{pphs}}
144 \index{pphs}
145 \index{pretty-printing Haskell code}
146 %*                                                                      *
147 %************************************************************************
148
149 Andrew Preece has written
150 \tr{pphs},\index{pphs}\index{pretty-printing Haskell}
151 a utility to pretty-print Haskell code in LaTeX documents.
152 Keywords in bolds, variables in italics---that sort of thing.  It is
153 good at lining up program clauses and equals signs, things that are
154 very tiresome to do by hand.
155
156 The code is distributed with GHC in \tr{ghc/CONTRIB/pphs}.