1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
<body bgcolor="#ffffff"> <i>The Hugs 98 User Manual</i><br> <a href="index.html">top</a> | <a href="commands.html">back</a> | <a href="exts.html">next</a> <br><hr>
<a name="libs"></a><a name="sect6"></a>
<h2>6<tt> </tt>Library overview</h2>
Haskell 98 places much greater emphasis on the use
of libraries than early versions of
the language. Following that lead, the Hugs 98
distribution includes most of the official libraries defined in the
Haskell Library Report [<a href="hugs.html#$Haskell98libs">Haskell98libs</a>].
The distribution also includes a number of unofficial libraries, which
fall into two categories: portable libraries, which are implemented using
standard Haskell or widely implemented Haskell extensions; and Hugs-specific
libraries, which use features that are not available in other Haskell
implementations. <p>
All that you need to do to use libraries is to import them
using an <tt>import</tt> declaration.
For example:
<tt><br>
module MandlebrotSet where<br>
import Array<br>
import Complex<br>
...<br>
</tt>Of course, this assumes
that <tt>HUGSPATH</tt> has
been set to point to the directories where the libraries are
stored, and
that import chasing is enabled.
The default search path includes the
directories containing both the standard and unofficial libraries.<p>
<a name="sect6.1"></a>
<h3>6.1<tt> </tt>Standard Libraries</h3>
The Hugs 98 distribution includes the following standard
libraries: <tt>Array</tt>, <tt>Char</tt>, <tt>Complex</tt>, <tt>IO</tt>, <tt>Ix</tt>, <tt>List</tt>, <tt>Locale</tt>, <tt>Maybe</tt>, <tt>Monad</tt>, <tt>Numeric</tt>, <tt>Prelude</tt>, <tt>Random</tt>, <tt>Ratio</tt>, and <tt>System</tt>.
The libraries <tt>Directory</tt>, <tt>Time</tt>, and <tt>CPUTime</tt>, are not currently supported.
The library report [<a href="hugs.html#$Haskell98libs">Haskell98libs</a>] contains full descriptions of all
of theses standard libraries. Differences between the library report and
the libraries supplied with Hugs are described in Section <a href="diffs.html#diffs">9</a>.<p>
<a name="sect6.2"></a>
<h3>6.2<tt> </tt>The Hugs-GHC Extension Libraries</h3>
Hugs and GHC provide a common set of libraries to aid portability; detailed
specifications for these libraries are described elsewhere [<a href="hugs.html#$HugsGHClibs">HugsGHClibs</a>].
The Hugs-GHC modules included in the current distribution
include <tt>Addr</tt>, <tt>Bits</tt>, <tt>Channel</tt>, <tt>ChannelVar</tt>, <tt>Concurrent</tt>, <tt>Dynamic</tt>, <tt>Foreign</tt>, <tt>IOExts</tt>, <tt>Int</tt>, <tt>GetOpt</tt>, <tt>NumExts</tt>, <tt>Pretty</tt>, <tt>ST</tt>, <tt>LazyST</tt>, <tt>Weak</tt>, and <tt>Word</tt>.
The <tt>Exception</tt> and <tt>Stable</tt> libraries are
not currently supported. Note that the <tt>ST</tt> and <tt>LazyST</tt> libraries
cannot be used when the interpreter is running in Haskell 98 mode; the type
for <tt>runST</tt> requires support for rank-2 polymorphism, which is only
available in Hugs mode. (See Section <a href="exts.html#ranktwo">7.3.2</a> for further details.)<p>
The specifications and implementations of all of these libraries are still
evolving, and are subject to change.<p>
<a name="sect6.3"></a>
<h3>6.3<tt> </tt>Portable Libraries</h3>
These libraries are not part of the Haskell standard but can be ported
to most Haskell systems.
<UL><LI><tt>ListUtils
</tt>This module provides list functions that were removed
from the Prelude in the move from Haskell 1.2 to Haskell 1.3.
<tt><br>
module ListUtils where<br>
<br>
sums, products :: Num a => [a] -> [a]<br>
subsequences :: [a] -> [[a]]<br>
permutations :: [a] -> [[a]]<br>
</tt><LI><tt>ParseLib
</tt>This module provides a library of parser combinators,
as described in the paper on <I>Monadic Parser Combinators</I> by
Graham Hutton and Erik Meijer [<a href="hugs.html#$MonParse">MonParse</a>].
<LI><tt>Interact</tt>:
This library provides facilities for writing simple interactive
programs.
<tt><br>
module Interact where<br>
<br>
type Interact = String -> String<br>
<br>
end :: Interact<br>
readChar, peekChar :: Interact -> (Char -> Interact) -> Interact<br>
pressAnyKey :: Interact -> Interact<br>
unreadChar :: Char -> Interact -> Interact<br>
writeChar :: Char -> Interact -> Interact<br>
writeStr :: String -> Interact -> Interact<br>
ringBell :: Interact -> Interact<br>
readLine :: String -> (String -> Interact) -> Interact<br>
</tt>An expression <tt>e</tt> of type <tt>Interact</tt> can be executed as a
program by evaluating <tt>run e</tt>.
<LI><tt>AnsiScreen
</tt>This library defines some basic ANSI escape seqences for terminal control.
<tt><br>
module AnsiScreen where<br>
<br>
type Pos = (Int,Int)<br>
<br>
at :: Pos -> String -> String<br>
highlight :: String -> String<br>
goto :: Int -> Int -> String<br>
home :: String<br>
cls :: String<br>
</tt>The definitions in this module will need to be adapted to work with
terminals that do not support ANSI escape sequences.
<LI><tt>AnsiInteract
</tt>This library includes both <tt>Interact</tt> and <tt>AnsiScreen</tt>, and
also contains further support for screen oriented interactive I/O.
<tt><br>
module AnsiInteract(module AnsiInteract,<br>
module Interact,<br>
module AnsiScreen) where<br>
import AnsiScreen<br>
import Interact<br>
<br>
clearScreen :: Interact -> Interact<br>
writeAt :: Pos -> String -> Interact -> Interact<br>
moveTo :: Pos -> Interact -> Interact<br>
readAt :: Pos -> -- start coords<br>
Int -> -- max input length<br>
(String -> Interact) -> -- continuation<br>
Interact<br>
defReadAt :: Pos -> -- start coords<br>
Int -> -- max input length<br>
String -> -- default value<br>
(String -> Interact) -> -- continuation<br>
Interact<br>
promptReadAt :: Pos -> -- start coords<br>
Int -> -- max input length <br>
String -> -- prompt<br>
(String -> Interact) -> -- continuation<br>
Interact<br>
defPromptReadAt :: Pos -> -- start coords<br>
Int -> -- max input length <br>
String -> -- prompt<br>
String -> -- default value<br>
(String -> Interact) -> -- continuation<br>
Interact<br>
</tt></UL><p>
<a name="sect6.4"></a>
<h3>6.4<tt> </tt>Hugs-Specific Libraries</h3>
These libraries provide several non-standard facilities for Hugs programmers.
Other Haskell implementations may provide similar features, but this is
not guaranteed, and there may be significant differences in organization,
naming, semantics, or functionality.
<UL><LI><tt>Number
</tt> This library defines a numeric datatype of
fixed width integers (whatever <tt>Int</tt> supplies). However,
unlike the built-in <tt>Int</tt> type, overflows are detected and
cause a run-time error. To ensure that all
integer arithmetic in a given module includes overflow protection
you must include a default declaration for <tt>Number</tt>.
<tt><br>
module Number where<br>
data Number -- fixed width integers<br>
instance Eq Number -- class instances<br>
instance Ord Number<br>
instance Show Number<br>
instance Enum Number<br>
instance Num Number<br>
instance Bounded Number<br>
instance Real Number<br>
instance Ix Number<br>
instance Integral Number<br>
</tt>This library cannot be used when Hugs is running in Haskell 98 mode
because it requires features that are only supported in full Hugs mode.
<LI><tt>IOExtensions
</tt>This module provides non-standard extensions to
the <tt>IO</tt> monad.
<tt><br>
module IOExtensions where<br>
<br>
readBinaryFile :: FilePath -> IO String<br>
writeBinaryFile :: FilePath -> String -> IO ()<br>
appendBinaryFile :: FilePath -> String -> IO ()<br>
openBinaryFile :: FilePath -> IOMode -> IO Handle<br>
<br>
getCh :: IO Char<br>
argv :: [String]<br>
</tt><LI><tt>Trace</tt>: This library provides
a single function, that can sometimes be useful for debugging:
<tt><br>
module Trace where<br>
trace :: String -> a -> a<br>
traceShow :: Show a => String -> a -> a<br>
</tt>When called, <tt>trace</tt> prints the string in its first argument, and then
returns the second argument as its result. The <tt>traceShow</tt> function is
a variant of <tt>trace</tt> that generates its output message by concatenating
the supplied <tt>String</tt> argument with the result of applying <tt>show</tt> to
its value argument. These functions are not
referentially transparent, and should only be used for debugging, or for
monitoring execution. You should also be warned that, unless you understand
some of the details about the way that Hugs programs are executed, results
obtained using <tt>trace</tt> can be rather confusing. For example, the
messages may not appear in the order that you expect. Even ignoring the
output that they produce, adding calls to <tt>trace</tt> can change the
semantics of your program. Consider this a warning!
<LI><tt>Trex
</tt>This library supports Trex extensible records. These can
only be used when Hugs is compiled with Trex support using
the <tt>-enable-TREX</tt> configuration option. Trex is described in
more details in Section <a href="exts.html#trex">7.2</a>.
<LI><tt>HugsInternals
</tt>This library provides primitives for accessing Hugs internals; for example,
they provide the means with which to implement simple error-recovery and
debugging facilities in Haskell.
They should be regarded as
an <I>experimental</I> feature and may not be supported in future
versions of Hugs. They can only be used if hugs was configured with
the <tt>--enable-internal-prims</tt> flag.
<LI><tt>GenericPrint
</tt>This library provides a "generic" (or "polymorphic") print function
in Haskell, that works in essentially the same way as Hugs' builtin
printer when the <tt>-u</tt> option is used.
The module <tt>HugsInternals</tt> is required.
<LI><tt>CVHAssert
</tt>This library provides a simple implementation of Cordy Hall's assertions
for performance debugging. These primitives are
an <I>experimental</I> feature that may be removed in future versions of Hugs.
They can only be used if hugs was configured with
the <tt>--enable-internal-prims</tt> flag.
<LI><tt>Win32
</tt>This library contains Haskell versions for many of the functions in
the Microsoft Win32 library. It is only available on Windows 95/NT.
The <tt>--with-plugins</tt> configuration option must be used in conjunction
with this and the other Microsoft libraries.
</UL>
Other libraries included in the standard distribution, but not further
documented here are <tt>Sequence</tt>, <tt>Pretty</tt>, <tt>HugsDynamic</tt>, <tt>HugsLibs</tt>, <tt>StdLibs</tt>,
and <tt>OldWeak</tt>.<p>
<hr><i>The Hugs 98 User Manual</i><br><a href="index.html">top</a> | <a href="commands.html">back</a> | <a href="exts.html">next</a> <br><font size=2>May 22, 1999</font>
|