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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
|
<body bgcolor="#ffffff"> <i>The Hugs 98 User Manual</i><br> <a href="index.html">top</a> | <a href="started.html">back</a> | <a href="libs.html">next</a> <br><hr>
<a name="commands"></a><a name="sect5"></a>
<h2>5<tt> </tt>Hugs commands</h2>
Hugs provides a number of commands that can be used to evaluate
expressions, to load files, and to inspect or modify the
behaviour of the system while the interpreter is running. Almost
all of the commands in Hugs begin with the <tt>:</tt> character,
followed by a short command word. For convenience, all but the first
letter of a command may be omitted. For
example, <tt>:l</tt>, <tt>:s</tt> and <tt>:q</tt> can be used as abbreviations
for the <tt>:load</tt>, <tt>:set</tt> and <tt>:quit</tt> commands, respectively.<p>
Most Hugs commands take arguments, separated from the command itself,
and from one another, by spaces. The Haskell syntax for string constants
can be used to enter parts of arguments that contain spaces, newlines, or
other special characters. For example, the command:
<tt><br>
:load My File<br>
</tt>will be treated as a command to load two files, <tt>My</tt> and <tt>File</tt>.
Any of the following commands can be used to load a
single file, <tt>My File</tt>, whose name includes an embedded space:
<tt><br>
:load "My File"<br>
:load "My\SPFile"<br>
:load "My\ \ File"<br>
:load My" "File<br>
</tt>You may wish to study the lexical syntax of Haskell strings to
understand some of these examples.
In practice, filenames do not usually include spaces or special
characters and can be entered without surrounding quotes, as in:
<tt><br>
:load fact.hs<br>
</tt>The full set of Hugs commands is described in the following sections.<p>
<a name="sect5.1"></a>
<h3>5.1<tt> </tt>Basic commands</h3><p>
<table border=2 cellpadding=3>
<tr><td><I>Evaluate expression</I> expr</td></tr></table>
To evaluate an expression, the user simply enters it at the Hugs
prompt.
This is treated as a special case, without the leading colon that
is required for other commands. The expression
must fit on a single line; there is no way to continue an expression
onto the next line of input to the interpreter. The actual
behaviour of the evaluator depends on the type of expr:
<UL><LI>If expr has type <tt>IO t</tt>, for some type <tt>t</tt>,
then it will be
treated as a program using the I/O facilities provided by the
Haskell <tt>IO</tt> monad. Any final result
produced by the computation will be discarded.
<tt><br>
Prelude> putStr "Hello, world"<br>
Hello, world<br>
Prelude> <br>
</tt><LI>In any other case, the value produced by the expression is
converted to a string by applying the <tt>show</tt> function from the
standard prelude, and the interpreter uses this to
print the result.
<tt><br>
Prelude> "Hello" ++ ", " ++ "world"<br>
"Hello, world"<br>
Prelude> <br>
</tt>Unlike some previous versions of Hugs, there is no
special treatment for values of type <tt>String</tt>; to display a string
without the enclosing quotes and special escapes, you should turn it
into a program using the <tt>putStr</tt> function,
as shown above.
</UL>
The interpreter will not evaluate an expression that contains a syntax
error, a type error, or a reference to an undefined variable:
<tt><br>
Prelude> sum [1..)<br>
ERROR: Syntax error in expression (unexpected `)')<br>
Prelude> sum 'a'<br>
ERROR: Type error in application<br>
*** expression : sum 'a'<br>
*** term : 'a'<br>
*** type : Char<br>
*** does not match : [a]<br>
Prelude> sum [1..n]<br>
ERROR: Undefined variable "n"<br>
Prelude> <br>
</tt>Another common problem occurs if there is no <tt>show</tt> function for the
expression entered---that is, if its type is not an instance of the
<tt>Show</tt> class. For example, suppose that a module defines a
type <tt>T</tt> without a <tt>Show</tt> instance:
<tt><br>
module Test where<br>
data T = A | B<br>
</tt>With just these definitions, any attempt to evaluate an expression of
type <tt>T</tt> will cause an error:
<tt><br>
Test> A<br>
ERROR: Cannot find "show" function for:<br>
*** expression : A<br>
*** of type : T<br>
Test> <br>
</tt>To avoid problems like this, you
will need to add an instance of the <tt>Show</tt> class
to your program. One of the simplest ways to do that is to request
a derived instance of <tt>Show</tt> as part of the datatype definition,
as in:
<tt><br>
module Test where<br>
data T = A | B deriving Show<br>
</tt>Once this has been loaded, Hugs will
evaluate and display values of type <tt>T</tt>:
<tt><br>
Test> A<br>
A<br>
Test> take 5 (cycle [A,B])<br>
[A, B, A, B, A]<br>
Test><br>
<p>
</tt>You should also note that the behaviour of the evaluator can be changed
while the interpreter is running by using
the <tt>:set</tt> command to
modify option settings.<p>
<table border=2 cellpadding=3>
<tr><td><I>View or change settings</I> :set [options]</td></tr></table>
Without any arguments, the <tt>:set</tt> command displays a list of
the options and their current settings.
The following output shows the settings on a typical machine:
<tt><br>
Prelude> :set<br>
TOGGLES: groups begin with +/- to turn options on/off resp.<br>
s Print no. reductions/cells after eval<br>
t Print type after evaluation<br>
f Terminate evaluation on first error<br>
g Print no. cells recovered after gc<br>
l Literate modules as default<br>
e Warn about errors in literate modules<br>
. Print dots to show progress<br>
q Print nothing to show progress<br>
w Always show which modules are loaded<br>
k Show kind errors in full<br>
u Use "show" to display results<br>
i Chase imports while loading modules<br>
<br>
<br>
OTHER OPTIONS: (leading + or - makes no difference)<br>
hnum Set heap size (cannot be changed within Hugs)<br>
pstr Set prompt string to str<br>
rstr Set repeat last expression string to str<br>
Pstr Set search path for modules to str<br>
Estr Use editor setting given by str<br>
cnum Set constraint cutoff limit<br>
Fstr Set preprocessor filter to str<br>
<br>
Current settings: +fewkui -stgl.q -h250000 -p"%s> " -r$$ -c40<br>
Search path : -P{Hugs}\lib;{Hugs}\lib\hugs;{Hugs}\lib\exts<br>
Editor setting : -E"vi +%d %s"<br>
Preprocessor : -F<br>
Compatibility : Haskell 98 (+98)<br>
Prelude><br>
</tt>The <tt>:set</tt> command can also be used to change options
by supplying the required settings as arguments. For example:
<tt><br>
Prelude> :set +st<br>
Prelude> 1 + 3<br>
4 :: Int<br>
(4 reductions, 4 cells)<br>
Prelude><br>
<p>
</tt>On Windows 95/NT, all option settings
are written out to the registry when a <tt>:set</tt> command is
executed, and will be used by subsequent executions of Hugs.<p>
<table border=2 cellpadding=3>
<tr><td><I>Shell escape</I> :![command]</td></tr></table>
A <tt>:!</tt>cmd command can be used to execute the system
command cmd without leaving the Hugs interpreter. For example,
<tt>:!ls</tt> (or <tt>:!dir</tt> on DOS machines) can be used to list the
contents of the current directory. For convenience, the <tt>:!</tt> command
can be abbreviated to a single <tt>!</tt> character.<p>
The <tt>:!</tt> command, without any arguments, starts a new shell:
<UL><LI>On a Unix machine, the <tt>SHELL</tt> environment variable is used to
determine which shell to use; the default is <tt>/bin/sh</tt>.
<LI>On an DOS machine, the <tt>COMSPEC</tt> environment variable is used
to determine which shell to use; this is usually <tt>COMMAND.COM</tt>.
</UL>
Most shells provide an <tt>exit</tt> command to terminate the
shell and return to Hugs.<p>
<table border=2 cellpadding=3>
<tr><td><I>List commands</I> :?</td></tr></table>
The <tt>:?</tt> command displays the following summary of all Hugs commands:
<tt><br>
Prelude> :?<br>
LIST OF COMMANDS: Any command may be abbreviated to :c where<br>
c is the first character in the full name.<br>
<br>
:load <filenames> load modules from specified files<br>
:load clear all files except prelude<br>
:also <filenames> read additional modules<br>
:reload repeat last load command<br>
:project <filename> use project file<br>
:edit <filename> edit file<br>
:edit edit last module<br>
:module <module> set module for evaluating expressions<br>
<expr> evaluate expression<br>
:type <expr> print type of expression<br>
:? display this list of commands<br>
:set <options> set command line options<br>
:set help on command line options<br>
:names [pat] list names currently in scope<br>
:info <names> describe named objects<br>
:browse <modules> browse names defined in <modules><br>
:find <name> edit module containing definition of name<br>
:!command shell escape<br>
:cd dir change directory<br>
:gc force garbage collection<br>
:version print Hugs version<br>
:quit exit Hugs interpreter<br>
Prelude><br>
<p>
</tt><table border=2 cellpadding=3>
<tr><td><I>Change module</I> :module module</td></tr></table>
A <tt>:module </tt>module command changes the current module to one
given by module. This is the module in which evaluation takes
place and in which objects named in commands are resolved. The specified
module must be part of the current program. If no module is specified, then
the last module to be loaded is assumed. (Note that the name of the current
module is usually displayed as part of the Hugs prompt.)<p>
<table border=2 cellpadding=3>
<tr><td><I>Change directory</I> :cd directory</td></tr></table>
A <tt>:cd </tt>dir command changes the current working directory
to the path given by dir. If no path is specified, then the
command is ignored.<p>
<table border=2 cellpadding=3>
<tr><td><I>Force a garbage collection</I> :gc</td></tr></table>
A <tt>:gc</tt> command can be used to force a garbage collection of the
interpreter heap, and to print the number of unused cells obtained as a
result:
<tt><br>
Prelude> :gc<br>
Garbage collection recovered 95766 cells<br>
Prelude> <br>
<p>
</tt><table border=2 cellpadding=3>
<tr><td><I>Exit the interpreter</I> :quit</td></tr></table>
The <tt>:quit</tt> command terminates the current Hugs session.<p>
<a name="sect5.2"></a>
<h3>5.2<tt> </tt>Loading and editing modules and projects</h3><p>
<table border=2 cellpadding=3>
<tr><td><I>Load definitions from module</I> :load [filename ...]</td></tr></table>
The <tt>:load</tt> command removes any previously loaded modules,
and then attempts to load the definitions from each of the listed files,
one after the other. If one of these files contains an error, then the
load process is suspended and a suitable error message will be displayed.
Once the problem has been corrected, the load process can be restarted
using a <tt>:reload</tt> command. On some systems,
the load process will be restarted automatically after
a <tt>:edit</tt> command.
(The exception occurs on Windows 95/NT because of the way that the
interpreter and editor are executed as independent processes.)<p>
If no file names are specified, the <tt>:load</tt> command just removes
any previously loaded definitions, leaving just the definitions provided
by the prelude.<p>
The <tt>:load</tt> command uses the list of directories specified by
the current path to search
for module files. We can specify the list of directory and filename pairs,
in the order that they are searched, using a Haskell list comprehension:
<tt><br>
[ (dir,file++suf) | dir <- [""] ++ path, suf <- ["", ".hs", ".lhs"]]<br>
</tt>The <tt>file</tt> mentioned here is the name of the module file that was
entered by the user, while <tt>path</tt> is the current Hugs search path.
The search starts with the directory <tt>""</tt>,
which usually represents a search relative to the current working
directory. So, the very first filename that the system tries to load
is <I>exactly</I> the same filename entered by the user. However, if
the named file cannot be accessed, then the system will try adding
a <tt>.hs</tt> suffix, and then a <tt>.lhs</tt> suffix, and then it will repeat
the process for each directory in the path, until either a suitable
file has been located, or, otherwise, until all of the possible choices
have been tried.
For example, this means that you do not have to type the <tt>.hs
</tt>suffix to load a file <tt>Demo.hs</tt> from the current directory,
provided that you do not already have a <tt>Demo</tt> file in the same
directory. In the same way, it is not usually necesary to include
the full pathname for one of the standard Hugs libraries. For example,
provided that you do not have an <tt>Array</tt>, <tt>Array.hs</tt>,
or <tt>Array.lhs</tt> file in the current working directory, you
can load the standard <tt>Array</tt> library
by typing just <tt>:load Array</tt>.<p>
<table border=2 cellpadding=3>
<tr><td><I>Load additional files</I> :also [filename ...]</td></tr></table>
The <tt>:also</tt> command can be used to load module files, without
removing any that have previously been loaded. (However, if any of
the previously
modules have been modified since they were last read, then they
will be reloaded automatically before the additional files are read.)<p>
If successful, a command of the form <tt>:load f1 .. fn</tt> is
equivalent to the sequence of commands:
<tt><br>
:load<br>
:also f1<br>
.<br>
.<br>
:also fn<br>
</tt>In particular, <tt>:also</tt> uses the same mechanisms
as <tt>:load</tt> to
search for modules.<p>
<table border=2 cellpadding=3>
<tr><td><I>Repeat last load command</I> :reload</td></tr></table>
The <tt>:reload</tt> command can be used to repeat the last load command.
If none of the previously loaded files has been modified since the last
time that it was loaded, then <tt>:reload</tt> will not have any effect.
However, if one of the modules has been modified, then it will be
reloaded. Note that modules are loaded in a specific order,
with the possibility that later modules may import
earlier ones. To allow for this, if one module has been reloaded, then all
subsequent modules will also be reloaded.<p>
This feature is particularly useful in a windowing environment. If the
interpreter is running in one window, then <tt>:reload</tt> can be used to
force the interpreter to take account of changes made by editing modules
in other windows.<p>
<table border=2 cellpadding=3>
<tr><td><I>Load project</I> :project [project file]</td></tr></table>
Project files were originally introduced to ease the task of working with
programs whose source code was spread over several files, all of
which had to be loaded at the same time. The facilities
for import chasing usually provide
a much better way to deal with multiple file projects, but the current
release of Hugs does still support the use of project files.<p>
The <tt>:project</tt> command takes a single argument; the name of a text
file containing a list of file names, separated from one another
by whitespace (which may include spaces, newlines, or Haskell-style
comments). For example, the following is a valid project file:
<tt><br>
{- A simple project file, Demo.prj -}<br>
Types -- datatype definitions<br>
Basics -- basic operations<br>
Main -- the main program<br>
</tt>If we load this into Hugs with a command <tt>:project Demo.prj</tt>,
then the interpreter will read the project file and then
try to load each of the named files. In this particular case, the overall
effect is, essentially, the same as that of:
<tt><br>
:load Types Basics Main<br>
</tt>Once a project file has been selected, the <tt>:project</tt> command
(without any arguments) can be used to force Hugs to reread both the
project file and the module files that it lists. This might be useful
if, for example, the project file itself has been modified since it
was first read.<p>
Project file names may also be specified on the command line when the
interpreter is invoked by preceding the project file name with a single
<tt>+</tt> character. Note that there must be at least one space on each side
of the <tt>+</tt>. Standard command line
options can also be used at the
same time, but additional filename arguments will be ignored. Starting Hugs
with a command of the form <tt>hugs + Demo.prj</tt> is equivalent to starting
Hugs without any arguments and then giving the
command <tt>:p Demo.prj</tt>.<p>
The <tt>:project</tt> command uses the same mechanisms
as <tt>:load</tt> to
locate the files mentioned in a project file, but it will not use
the current path to locate
the project file itself; you must specify a full pathname.<p>
As has already been said, import chasing usually provides a much better
way to deal with multiple file programs than the old project file system.
The big advantage of import chasing is that dependencies between modules
are documented within individual modules,
leaving the system free to determine the order in which the files should
be loaded. For example, if the <tt>Main</tt> module in the example above
actually needs the definitions in <tt>Types</tt> and <tt>Basics</tt>, then
this will be documented by import statements, and the whole program could
be loaded with a single <tt>:load Main</tt> command.<p>
<table border=2 cellpadding=3>
<tr><td><I>Edit file</I> :edit [file]</td></tr></table>
The <tt>:edit</tt> command starts an editor program to modify or view a
module file. On Windows 95/NT, the editor and interpreter are executed
as independent processes. On other systems, the current Hugs session
will be suspended while the editor is running. Then, when the editor
terminates, the Hugs session will be resumed and any files that have
been changed will be reloaded automatically.
The <tt>-E</tt> option should be used to configure Hugs to
your preferred choice of editor.<p>
If no filename is specified, then Hugs uses the name of the last
file that it tried to load. This allows the <tt>:edit</tt> command
to integrate smoothly with the facilities for loading files.<p>
For example, suppose that you want to load four
files, <tt>f1.hs</tt>, <tt>f2.hs</tt>, <tt>f3.hs</tt> and <tt>f4.hs</tt> into the
interpreter, but the file <tt>f3.hs</tt> contains an error of some kind.
If you give the command:
<tt><br>
:load f1 f2 f3 f4<br>
</tt>then Hugs will successfully load <tt>f1.hs</tt> and <tt>f2.hs</tt>, but will
abort the load command when it encounters the error in <tt>f3.hs</tt>,
printing an error message to describe the problem that occured.
Now, if you use the command:
<tt><br>
:edit<br>
</tt>then Hugs will start up the editor with the cursor positioned at the
relevant line of <tt>f3.hs</tt> (whenever this is possible) so that the
error can be corrected and the changes saved in <tt>f3.hs</tt>.
When you close down the editor and return to Hugs, the
interpreter will automatically attempt to reload <tt>f3.hs</tt> and then,
if successful, go on to load the next file, <tt>f4.hs</tt>.
So, after just two commands in Hugs, the error in <tt>f3.hs</tt> has been
corrected and all four of the files listed on the original command
line have been loaded into the interpreter, ready for use.<p>
<table border=2 cellpadding=3>
<tr><td><I>Find definition</I> :find name</td></tr></table>
The <tt>:find </tt>name command starts up the editor at the definition
of a type constructor or function, specified by the argument name,
in one of the files currently loaded into Hugs. Note that Hugs must be
configured with an appropriate editor for
this to work properly.
There are four possibilities:
<UL><LI>If there is a type constructor with the specified name, then
the cursor will be positioned at the first line in the definition of
that type constructor.
<LI>If the name is defined by a function or variable binding, then
the cursor will be positioned at the first line in the definition of
the function or variable (ignoring any type declaration, if present).
<LI>If the name is a constructor function or a selector function
associated with a particular datatype, then the cursor will be
positioned at the first line in the definition of the
corresponding datatype definition.
<LI>If the name represents an internal Hugs function, then the
cursor will be positioned at the beginning of the standard
prelude file.
</UL>
Note that names of infix operators should be given without any
enclosing them in parentheses. Thus <tt>:f !!</tt> starts an editor on the
standard prelude at the first line in the definition of <tt>(!!)</tt>.
If a given name could be interpreted both as a type constructor and as
a value constructor, then the former is assumed.<p>
<a name="sect5.3"></a>
<h3>5.3<tt> </tt>Finding information about the system</h3><p>
<table border=2 cellpadding=3>
<tr><td><I>List names</I> :names [pattern ...]</td></tr></table>
The <tt>:names</tt> command can be used to list the names of variables and
functions whose definitions are currently loaded into the interpreter.
Without any arguments, <tt>:names</tt> produces a list of all names known
to the system; the names are listed in alphabetical order.<p>
The <tt>:names</tt> command can also accept one or more pattern strings,
limiting the list of names that will be printed to those matching one or more
of the given pattern strings:
<tt><br>
Prelude> :n fold*<br>
foldl foldl' foldl1 foldr foldr1<br>
(5 names listed)<br>
Prelude><br>
</tt>Each pattern string consists of a string of characters and may use
standard wildcard syntax: <tt>*</tt> (matches anything), <tt>?</tt> (matches
any single character), <tt>\c</tt> (matches exactly the character <tt>c</tt>)
and ranges of characters of the form <tt>[a-zA-Z]</tt>, etc. For example:
<tt><br>
Prelude> :n *map* *[Ff]ile ?<br>
$ % * + - . / : < > appendFile map mapM mapM_ readFile writeFile ^<br>
(17 names listed)<br>
Prelude><br>
<p>
</tt><table border=2 cellpadding=3>
<tr><td><I>Print type of expression</I> :type expr</td></tr></table>
The <tt>:type</tt> command can be used to print the type of an expression
without evaluating it. For example:
<tt><br>
Prelude> :t "hello, world"<br>
"hello, world" :: String<br>
Prelude> :t putStr "hello, world"<br>
putStr "hello, world" :: IO ()<br>
Prelude> :t sum [1..10]<br>
sum (enumFromTo 1 10) :: (Num a, Enum a) => a<br>
Prelude><br>
</tt>Note that Hugs displays the most general type that can be inferred
for each expression. For example, compare the type inferred
for <tt>sum [1..10]</tt> above with the type printed by the evaluator
(using <tt>:set +t</tt>):
<tt><br>
Prelude> :set +t<br>
Prelude> sum [1..10]<br>
55 :: Int<br>
Prelude><br>
</tt>The difference is explained by the fact that the evaluator uses the Haskell
default mechanism to instantiate the type variable <tt>a</tt> in the most
general type to the type <tt>Int</tt>, avoiding an error with unresolved
overloading.<p>
<table border=2 cellpadding=3>
<tr><td><I>Display information about names</I> :info [name ...]</td></tr></table>
The <tt>:info</tt> command is useful for obtaining information about the
files, classes, types and values that are currently loaded.<p>
If there are no arguments, then <tt>:info</tt> prints a list of all the
files that are currently loaded into the interpreter.
<tt><br>
Prelude> :info<br>
Hugs session for:<br>
/Hugs/lib/Prelude.hs<br>
Demo.hs<br>
Prelude> <br>
</tt>If there are arguments, then Hugs treats each one as a name, and displays
information about any corresponding type constructor, class, or function.
The following examples show the the kind of output that you can expect:
<UL><LI>Datatypes: The system displays the name of the datatype, the names
and types of any constructors or selectors, and a summary of related
instance declarations:
<tt><br>
Prelude> :info Either<br>
-- type constructor<br>
data Either a b<br>
<br>
-- constructors:<br>
Left :: a -> Either a b<br>
Right :: b -> Either a b<br>
<br>
-- instances:<br>
instance (Eq b, Eq a) => Eq (Either a b)<br>
instance (Ord b, Ord a) => Ord (Either a b)<br>
instance (Read b, Read a) => Read (Either a b)<br>
instance (Show b, Show a) => Show (Either a b)<br>
instance Eval (Either a b)<br>
<br>
Prelude><br>
</tt>Newtypes are dealt with in exactly the same way.
For a simple example of a datatype with selectors, the output produced
for a <tt>Time</tt> datatype:
<tt><br>
data Time = MkTime { hours, mins, secs :: Int }<br>
</tt>is as follows:
<tt><br>
Time> :info Time<br>
-- type constructor<br>
data Time<br>
<br>
-- constructors:<br>
MkTime :: Int -> Int -> Int -> Time<br>
<br>
-- selectors:<br>
hours :: Time -> Int<br>
mins :: Time -> Int<br>
secs :: Time -> Int<br>
<br>
-- instances:<br>
<br>
instance Eval Time<br>
<br>
Time><br>
</tt><LI>Type synonyms: The system displays the name and expansion:
<tt><br>
Prelude> :info String<br>
-- type constructor<br>
type String = [Char]<br>
<br>
Prelude><br>
</tt>The expansion is not included in the output if the synonym is
restricted. <LI>Type classes: The system lists the name, superclasses, members, and
instance declarations for the specified class:
<tt><br>
Prelude> :info Num<br>
-- type class<br>
class (Eq a, Show a, Eval a) => Num a where<br>
(+) :: a -> a -> a<br>
(-) :: a -> a -> a<br>
(*) :: a -> a -> a<br>
negate :: a -> a<br>
abs :: a -> a<br>
signum :: a -> a<br>
fromInteger :: Integer -> a<br>
fromInt :: Int -> a<br>
<br>
-- instances:<br>
instance Num Int<br>
instance Num Integer<br>
instance Num Float<br>
instance Num Double<br>
instance Integral a => Num (Ratio a)<br>
<br>
Prelude><br>
</tt><LI>Other values: For example, named functions and individual
constructor, selector, and member functions are displayed with their name
and type:
<tt><br>
Time> :info . : hours min<br>
(.) :: (a -> b) -> (c -> a) -> c -> b<br>
<br>
(:) :: a -> [a] -> [a] -- data constructor<br>
<br>
hours :: Time -> Int -- selector function<br>
<br>
min :: Ord a => a -> a -> a -- class member<br>
<br>
Time><br>
</tt></UL>
As the last example shows, the <tt>:info</tt> command can take several arguments
and prints out information about each in turn. A warning message is
displayed if there are no known references to an argument:
<tt><br>
Prelude> :info (:)<br>
Unknown reference `(:)'<br>
Prelude><br>
</tt>This illustrates that the arguments are treated as textual names for
operators, not syntactic expressions (for example, identifiers). The
type of the <tt>(:)</tt> operator can be obtained using the command
<tt>:info :</tt> as above. There is no provision for including wildcard
characters of any form in the arguments of <tt>:info</tt> commands.<p>
If a particular argument can be interpreted as, for example, both a
constructor function, and a type constructor, depending on context, then
the output for both possibilities will be displayed.<p>
<table border=2 cellpadding=3>
<tr><td><I>Display names defined in modules</I> :browse [module ...]</td></tr></table>
The <tt>:browse</tt> command can be used to display the list of
functions that are exported from the named modules:
<tt><br>
List> :browse Maybe<br>
module Maybe where<br>
mapMaybe :: (a -> Maybe b) -> [a] -> [b]<br>
catMaybes :: [Maybe a] -> [a]<br>
listToMaybe :: [a] -> Maybe a<br>
maybeToList :: Maybe a -> [a]<br>
fromMaybe :: a -> Maybe a -> a<br>
fromJust :: Maybe a -> a<br>
isNothing :: Maybe a -> Bool<br>
isJust :: Maybe a -> Bool<br>
List><br>
</tt>Only the names of currently loaded modules will be recognized.<p>
<table border=2 cellpadding=3>
<tr><td><I>Display Hugs version</I> :version</td></tr></table>
The <tt>:version</tt> command is used to display the version of
the Hugs interpreter:
<tt><br>
Prelude> :version<br>
-- Hugs Version September 1999<br>
Prelude><br>
</tt>This is the same information that is displayed in the Hugs
startup banner.<p>
<hr><i>The Hugs 98 User Manual</i><br><a href="index.html">top</a> | <a href="started.html">back</a> | <a href="libs.html">next</a> <br><font size=2>May 22, 1999</font>
|