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 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
|
<chapter id="options">
<title>Changing the behaviour of Hugs</title>
<sect1 id="options-list">
<title>Hugs options</title>
<para>
The behaviour of Hugs may be modified by options.
These are initially set to default values,
and then read from the following sources in order:
<orderedlist>
<listitem>
<para>
(Windows only) the registry under the <literal>HKEY_LOCAL_MACHINE</literal> key.
</para>
</listitem>
<listitem>
<para>
(Windows only) the registry under the <literal>HKEY_CURRENT_USER</literal> key.
This step is skipped if the environment variable
<envar>IGNORE_USER_REGISTRY</envar> is set,
providing an emergency workaround if the settings are invalid.
</para>
</listitem>
<listitem>
<para>
(Hugs for Windows only)
the GUI settings.
</para>
</listitem>
<listitem>
<para>
(Mac OS prior to Mac OS X)
the preferences file <quote><filename>Hugs Preferences</filename></quote>.
</para>
</listitem>
<listitem>
<para>
The environment variable <envar>HUGSFLAGS</envar>, if set.
</para>
</listitem>
<listitem>
<para>
The Hugs command line.
</para>
</listitem>
</orderedlist>
Most options can be changed within Hugs using the <command>:set</command>
command (see <xref linkend="basic-commands"/>).
</para>
<para>
Hugs takes two kinds of options:
<itemizedlist>
<listitem>
<para>
Toggles like <option>+t</option> or <option>-t</option>,
which start with <literal>+</literal> or <literal>-</literal>
to turn them on or off, respectively.
</para>
</listitem>
<listitem>
<para>
Options that set a parameter value, like
<option>-P</option><replaceable>str</replaceable>,
in which <literal>-</literal> could be replaced by <literal>+</literal>,
the choice making no difference.
</para>
</listitem>
</itemizedlist>
</para>
<sect2 id="options-language">
<title>Language options</title>
<variablelist>
<varlistentry id="option-98">
<term><option>+98</option></term>
<listitem>
<para>
Accept only Haskell 98.
This is on by default, and cannot be changed within Hugs.
Turning this off enables several special Hugs extensions,
which are described in <xref linkend="hugs-ghc"/>, <xref linkend="hugs-only"/>
and the <citetitle pubwork="article">Hugs 98 User Manual</citetitle>.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-constraint-cutoff">
<term><option>-c</option><replaceable>num</replaceable></term>
<listitem>
<para>
Set constraint cutoff limit in the type checker to
<replaceable>num</replaceable> (default: 40).
See <xref linkend="flexible-instances"/>.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-overlapping">
<term><option>+o</option></term>
<listitem>
<para>
Allow certain overlapping instances (a Hugs extension; default: off).
See <xref linkend="overlapping-instances"/> for details.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-unsafe-overlapping">
<term><option>+O</option></term>
<listitem>
<para>
Allow certain overlapping instances (a Hugs extension; default: off).
These are the same overlapping instances as accepted by <option>+o</option>,
but <option>+O</option> also accepts ambiguous uses of these instances,
even though this is unsafe (see <xref linkend="overlapping-instances"/>).
</para>
</listitem>
</varlistentry>
<varlistentry id="option-here-documents">
<term><option>+H</option></term>
<listitem>
<para>
Support <emphasis>here documents</emphasis>
(named after similar things in Unix shells),
another way of writing large string literals
(see <xref linkend="here-documents"/>).
This extension is turned off by default.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="options-loading">
<title>Module loading options</title>
<variablelist>
<varlistentry id="option-literate">
<term><option>+l</option></term>
<listitem>
<para>
Literate scripts as default (default: off).
</para>
<para>
Files with names ending in <quote><literal>.hs</literal></quote>
are always treated as ordinary Haskell,
while those ending in <quote><literal>.lhs</literal></quote>
are always treated as literate scripts.
This option determines whether other files are literate scripts or not.
(See <xref linkend="runhugs"/> for an example.)
</para>
</listitem>
</varlistentry>
<varlistentry id="option-dots">
<term><option>+.</option></term>
<listitem>
<para>
Print dots to show progress while loading modules (default: off).
</para>
</listitem>
</varlistentry>
<varlistentry id="option-quiet">
<term><option>+q</option></term>
<listitem>
<para>
Print nothing to show progress while loading modules (default: on).
</para>
</listitem>
</varlistentry>
<varlistentry id="option-show-loaded">
<term><option>+w</option></term>
<listitem>
<para>
Always show which files were loaded (default: off).
</para>
</listitem>
</varlistentry>
<varlistentry id="option-preprocessor">
<term><option>-F</option><replaceable>cmd</replaceable></term>
<listitem>
<para>
Preprocess source files before loading.
Instead of reading a source file directly, Hugs will
execute <replaceable>cmd</replaceable> with the source file name as argument,
and read the standard output.
</para>
<para>
This is handy for preprocessing source files with the C preprocessor,
or some preprocessor implementing a language extension.
However it is slower.
In particular (because of the way Hugs handles imports),
the preprocessor will be run twice on files that import modules
that have not been loaded yet.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-search-path">
<term><option>-P</option><replaceable>str</replaceable></term>
<listitem>
<para>
Set search path for source files to <replaceable>str</replaceable>,
which should be a list of directories separated by colons
(semicolons on Windows, DOS or Macs).
A null entry in this list will be replaced by the previous search path;
a null <replaceable>str</replaceable> means the default path.
Any occurrences of <literal>{Hugs}</literal> in this string will be replaced
by the Hugs library directory.
Similarly, <literal>{Home}</literal> is expanded to your home directory.
An entry of the form
<quote><replaceable>directory</replaceable><literal>/*</literal></quote>
means all the immediate subdirectories of <replaceable>directory</replaceable>.
The default value is
<programlisting>
.:{Hugs}/libraries:{Hugs}/oldlib
</programlisting>
</para>
<para>
The interpreter won't let you change the search path if that would
prevent it from reading the <literal>Prelude</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-suffixes">
<term><option>-S</option><replaceable>str</replaceable></term>
<listitem>
<para>
Set list of filename suffixes.
</para>
<para>
Normally, when you import a module <replaceable>M</replaceable>,
Hugs looks for files <replaceable>M</replaceable><literal>.hs</literal>
and <replaceable>M</replaceable><literal>.lhs</literal>
in each directory in you search path.
With this option, you can change this list,
in a similar way to the <option>-P</option> option for the search path.
By default, the suffix list is <quote><literal>.hs:.lhs</literal></quote>,
which gives the behaviour just described.
(NB: the <quote><literal>:</literal></quote> is the Unix separator.
Windows or Macs use <quote><literal>;</literal></quote> instead.)
If you use <literal>-S:.xhs</literal> then the suffix
list becomes <quote><literal>.hs:.lhs:.xhs</literal></quote>,
so Hugs will look for
<replaceable>M</replaceable><literal>.hs</literal>,
<replaceable>M</replaceable><literal>.lhs</literal>
and <replaceable>M</replaceable><literal>.xhs</literal>.
</para>
<para>
A null entry in this list will be replaced by the previous suffix list;
a null <replaceable>str</replaceable> means the default list.
</para>
<para>
The interpreter won't let you change the suffix list if that would
prevent it from reading the <literal>Prelude</literal>,
i.e. you must include <quote><literal>.hs</literal></quote>.
Note also that the interpreter knows that files ending in
<quote><literal>.lhs</literal></quote> are literate scripts;
no other suffix is treated that way.
</para>
<para>
This option can be useful in conjunction with the preprocessor option
(<option>-F</option>).
The preprocessor can examine the filename to decide what to do with the file.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="options-editor">
<title>Specifying a source file editor</title>
<variablelist>
<varlistentry id="option-editor">
<term><option>-E</option><replaceable>str</replaceable></term>
<listitem>
<para>
Specify the editor used by the <literal>:edit</literal> command
(see <xref linkend="module-commands"/>).
For example, to have Hugs invoke <literal>vi</literal> to edit your files,
use
<programlisting>
-Evi
</programlisting>
The argument string is actually a template string that gets expanded
by Hugs, via the following rules:
<itemizedlist>
<listitem>
<para>
all occurrences of <literal>%d</literal> are replaced by the line number
of where the last error occurred (if any).
Please consult your editor's documentation for ways of specifying the
line number.
</para>
</listitem>
<listitem>
<para>
all occurrences of <literal>%s</literal> are replaced by the name of the file.
If an occurrence of <literal>%s</literal> is both preceded by and followed
by space, the filename is enclosed in double-quotes.
</para>
</listitem>
<listitem>
<para>
all occurrences of <literal>%f</literal> are replaced by the absolute filename
(provided your platform lets you find the absolute path to a file.)
Most of the time, <literal>%s</literal> will be just fine, but in case your
editor doesn't handle relative filenames correctly, try
using <literal>%f</literal>.
</para>
</listitem>
<listitem>
<para>
all occurrences of <literal>%%</literal> are replaced by <literal>%</literal>.
</para>
</listitem>
<listitem>
<para>
(win32 only): if the <option>-E</option> string is prefixed with
the character <quote><literal>&</literal></quote>,
then the invocation is asynchronous, that is, the editor process
is created, but Hugs won't wait for the editor to terminate.
</para>
</listitem>
<listitem>
<para>
(win32 only): if the <option>-E</option> string is prefixed with
the character <quote><literal>!</literal></quote>,
then the invocation will be asynchronous and use the underlying
command processor/shell to execute the command.
</para>
</listitem>
</itemizedlist>
If neither <literal>%s</literal> nor <literal>%f</literal> occurs within
the <option>-E</option> string,
then the filename is appended before invoking the editor.
</para>
<para>
Here are some example editor configurations:
<itemizedlist>
<listitem>
<para>
TextPad
<programlisting>
-E"c:/Program Files/TextPad 4/textpad \"%s\"(%d)"
</programlisting>
</para>
</listitem>
<listitem>
<para>
vi and clones
<programlisting>
-E"vi +%d %s"
</programlisting>
</para>
</listitem>
<listitem>
<para>
gnuclient (for use with (X)Emacs)
<programlisting>
-E"gnuclient +%d %s"
</programlisting>
</para>
</listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="options-evaluation">
<title>Evaluation and printing options</title>
<variablelist>
<varlistentry id="option-prompt">
<term><option>-p</option><replaceable>str</replaceable></term>
<listitem>
<para>
Set prompt string to <replaceable>str</replaceable>
(default: <quote><literal>%s> </literal></quote>).
Any <literal>%s</literal> in <replaceable>str</replaceable>
will be replaced by the current module name.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-repeat-string">
<term><option>-r</option><replaceable>str</replaceable></term>
<listitem>
<para>
Set the string denoting the last expression to <replaceable>str</replaceable>
(default: <quote><literal>$$</literal></quote>).
</para>
</listitem>
</varlistentry>
<varlistentry id="option-full-kind-errors">
<term><option>+k</option></term>
<listitem>
<para>
Show kind errors in full (default: off).
</para>
<para>
In Haskell, each type expression has a <emphasis>kind</emphasis>.
These kinds do not appear in the source language,
but they are checked for consistency.
By default, Hugs reports such errors as an <literal>Illegal type</literal>.
For example, the declaration
<programlisting>
instance Monad Int
</programlisting>
gives rise to the error
<screen>
ERROR "Test.hs":4 - Illegal type in class constraint
</screen>
However if <option>+k</option> is given,
the error message is identified as a <literal>Kind error</literal>,
and is expanded to include the conflicting kinds:
<screen>
ERROR "Test.hs":4 - Kind error in class constraint
*** constructor : Int
*** kind : *
*** does not match : * -> *
</screen>
Also, when <option>+k</option> is given,
the output of the <command>:info</command> will include kind information
for classes and type constructors:
<screen>
Prelude> :info Monad
-- constructor class with arity * -> *
...
Prelude> :info Int
-- type constructor with kind *
</screen>
</para>
</listitem>
</varlistentry>
<varlistentry id="option-default-types">
<term><option>+T</option></term>
<listitem>
<para>
Apply defaulting rules to types before printing (default: off).
</para>
<para>
When printing out types, the interpreter will normally not try to
simplify types by applying defaulting rules, e.g.,
<screen>
Prelude> :t 1
1 :: Num a => a
Prelude>
</screen>
With the <option>+T</option> option,
the interpreter attempts to <quote>default</quote> types first,
using the same rules as for expressions (see <xref linkend="basic-commands"/>):
<screen>
Prelude> :set +T
Prelude> :t 1
1 :: Integer
Prelude>
</screen>
</para>
</listitem>
</varlistentry>
<varlistentry id="option-qualify-names">
<term><option>+Q</option></term>
<listitem>
<para>
Qualify names when printing (default: off).
</para>
<para>
By default, the interpreter will print out names without qualifying
them with their defining modules.
Most of the time that's exactly what you want,
but can become confusing if you re-define types and functions;
the error messages not pinning down what entity it is referring to.
To have the interpreter qualify the names, use <option>+Q</option>.
Typically, you use <option>+Q</option> when resolving errors,
but turn it back off again afterwards.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-print-type">
<term><option>+t</option></term>
<listitem>
<para>
Print the type of each expression evaluated (default: off).
</para>
<para>
Normally Hugs merely prints the value of each expression evaluated:
<screen>
Prelude> 1+2
3
</screen>
With the <option>+t</option> option, it also adds the type of the expression:
<screen>
Prelude> :set +t
Prelude> 1+2
3 :: Integer
</screen>
Note that defaulting has been applied to the type of the expression in order
to evaluate it, so the type differs from that reported by the
<command>:type</command> command (assuming that the
<link linkend="option-default-types"><option>+T</option></link> option
is not used):
<screen>
Prelude> :type 1+2
1 + 2 :: Num a => a
</screen>
</para>
</listitem>
</varlistentry>
<varlistentry id="option-use-show">
<term><option>+u</option></term>
<listitem>
<para>
Use <literal>show</literal> to display results (default: on).
</para>
<para>
By default, the values of expressions typed at the prompt are printed using
the <literal>show</literal> member of the <literal>Show</literal> class:
<screen>
Prelude> [Just (2+3), Nothing]
[Just 5,Nothing]
</screen>
You can define this function as desired for any new datatype.
If the type of the expression is not an instance of the
<literal>Show</literal> class, an error results:
<screen>
Prelude> id
ERROR - Cannot find "show" function for:
*** Expression : id
*** Of type : a -> a
</screen>
With the <option>-u</option> option, a built-in printer is used instead,
and this works for any type:
<screen>
Prelude> :set -u
Prelude> id
id
Prelude> \x -> x
v1497
Prelude> [Just (2+3), Nothing]
[Maybe_Just 5,Maybe_Nothing]
</screen>
Another feature of the built-in printer is its treatment of failures
(or exceptions).
Normally, an exception causes immediate failure of the expression:
<screen>
Prelude> :set +u
Prelude> 1 + 2/0
Program error: divide by zero
Prelude> [1, 2 + error "foo", 3]
[1,
Program error: foo
</screen>
However the built-in printer prints the whole value, with embedded exceptions:
<screen>
Prelude> :set -u
Prelude> [1, 2 + error "foo", 3]
[1,{error "foo"},3]
</screen>
Sometimes a component could produce one of two or more exceptions,
but the built-in printer shows only one of them:
<screen>
Prelude> 1 + error "foo" + error "bar"
{error "foo"}
</screen>
</para>
</listitem>
</varlistentry>
<varlistentry id="option-display-io">
<term><option>+I</option></term>
<listitem>
<para>
Display results of IO programs (default: off).
</para>
<para>
By default, an expression of <literal>IO</literal> type typed at the prompt
is executed for effect, but the final value it produces is discarded.
When <option>+I</option> is used, such an expression is evaluated,
and then its result is printed with <literal>Prelude.print</literal>:
<screen>
Prelude> :set +I
Prelude> (return 'a' :: IO Char)
'a'
Prelude>
</screen>
i.e., evaluating an IO action <replaceable>m</replaceable>
with <option>+I</option> in effect is equivalent to evaluating
<quote><literal>do { x <- m ; print x }</literal></quote>
with <option>-I</option>.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="options-resource">
<title>Resource usage options</title>
<variablelist>
<varlistentry id="option-heap-size">
<term><option>-h</option><replaceable>num</replaceable></term>
<listitem>
<para>
Set the maximum size in the Hugs heap (default: <literal>250k</literal>).
The argument should be a decimal number, and may by suffixed with
<quote><literal>k</literal></quote> (thousands),
<quote><literal>M</literal></quote> (millions) or
<quote><literal>G</literal></quote>
(billions, if your machine has that much memory).
Case is not significant.
The heap size is measured in cells,
each of which usually comprises two <literal>int</literal>s
(taking up 8 bytes on most common architectures).
</para>
<para>
Setting this option with <command>:set</command> does not change the heap
size for the current execution of Hugs.
On Win32, however, all options are saved to the registry,
so it will take effect the next time Hugs is run.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-print-reductions">
<term><option>+s</option></term>
<listitem>
<para>
Print statistics after each evaluation (default: off).
</para>
<para>
For each evaluation, this option shows
<itemizedlist>
<listitem><para>
the number of reductions performed (a crude measure of the amount of
work performed by the interpreter),
</para></listitem>
<listitem><para>
the total number of cells allocated during evaluation, and
</para></listitem>
<listitem><para>
the number of garbage collections that occurred during evaluation (if any).
</para></listitem>
</itemizedlist>
Note that even the most trivial evaluation involves several reductions and
cells, because Hugs wraps the expression in code to print the value and
catch exceptions:
<screen>
Prelude> True
True
(25 reductions, 46 cells)
</screen>
Note that the cell count measures the total amount of allocation,
rather than the number of cells in use at any time
(the <emphasis>residency</emphasis>).
For that, the <link linkend="option-print-gc"><option>+g</option></link>
option may be more useful.
In general these statistics cannot be safely used for much more than
spotting general trends.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-print-gc">
<term><option>+g</option></term>
<listitem>
<para>
Print the number of cells recovered after each garbage collection
(default: off).
This can be useful for analysing the <emphasis>residency</emphasis> of an
algorithm, the amount of memory is is actually using at each point in time.
For example,
<screen>
Prelude> :set +g
Prelude> length [1..60000]
{{Gc:237618}}{{Gc:237617}}{{Gc:237616}}{{Gc:237623}}{{Gc:237621}}
{{Gc:237628}}{{Gc:237623}}{{Gc:237618}}60000
</screen>
We see that the computation creates a lot of cells, but the number recovered
on each garbage collection is roughly the same, so its residency is constant.
In contrast, with
<screen>
Prelude> let xs = [1..60000] in sum xs `div` length xs
{{Gc:237510}}{{Gc:213862}}{{Gc:190948}}{{Gc:170500}}{{Gc:152225}}
{{Gc:135925}}{{Gc:121350}}{{Gc:108350}}{{Gc:96750}}{{Gc:86375}}
{{Gc:77125}}{{Gc:68860}}{{Gc:61490}}{{Gc:72948}}{{Gc:97265}}{{Gc:129688}}
{{Gc:172916}}{{Gc:230551}}30000
</screen>
we see that the amount reclaimed by each garbage collection is steadily
falling until a certain point (because the original list is retained).
These examples use the default heap size of 250000 cells;
this may be changed with the
<link linkend="option-heap-size"><option>-h</option></link> option.
</para>
<para>
Since these garbage collection messages will be unpredictably interleaved
with the desired output, you would usually only turn <option>+g</option>
on to analyse memory problems, and then turn it off afterwards.
</para>
</listitem>
</varlistentry>
<varlistentry id="option-root-optimisation">
<term><option>+R</option></term>
<listitem>
<para>
Enable root optimisation (default: on).
</para>
<para>
This usually gives a small gain in speed, but you might want to turn it off
if you're using the observation-based debugger
(see <xref linkend="observe-and-root-optimisation"/>).
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>
<sect1 id="environment-variables">
<title>Environment variables used by Hugs</title>
<para>
Hugs also consults a number of environment variables
on systems that support them.
The method for setting these varies with the system.
</para>
<variablelist>
<varlistentry id="EMACS">
<term><envar>EMACS</envar></term>
<listitem>
<para>
(Windows only)
If this variable is set, Hugs is assumed to be running in an Emacs subshell
(with different line termination conventions on input).
</para>
</listitem>
</varlistentry>
<varlistentry id="HOME">
<term><envar>HOME</envar></term>
<listitem>
<para>
The user's home directory.
This is substituted for <literal>{Home}</literal> in the argument of the
<link linkend="option-search-path"><option>-P</option></link> option
(see <xref linkend="options-loading"/>),
and for <quote><literal>~</literal></quote> in the argument of the
<command>:cd</command> command
(see <xref linkend="misc-commands"/>).
</para>
</listitem>
</varlistentry>
<varlistentry id="HUGSFLAGS">
<term><envar>HUGSFLAGS</envar></term>
<listitem>
<para>
Additional options for Hugs, processed before any given on the command line
(see <xref linkend="options-list"/>).
Within this string, options may be separated by whitespace.
To include a literal space in an option, either precede it with a backslash
or wrap the whole option in double quotes.
The following example assumes a shell compatible with the Unix Bourne shell:
<programlisting>
HUGSFLAGS='+k -E"vi +%d"'
export HUGSFLAGS
</programlisting>
Double quoted options may also contain the escape sequences
<quote><literal>\ </literal></quote>,
<quote><literal>\"</literal></quote> and
<quote><literal>\\</literal></quote>.
Other bachslashes are interpreted literally.
</para>
</listitem>
</varlistentry>
<varlistentry id="HUGSDIR">
<term><envar>HUGSDIR</envar></term>
<listitem>
<para>
The Hugs library directory.
This is substituted for <literal>{Hugs}</literal> in the argument of the
<link linkend="option-search-path"><option>-P</option></link> option
(see <xref linkend="options-loading"/>).
</para>
</listitem>
</varlistentry>
<varlistentry id="IGNORE-USER-REGISTRY">
<term><envar>IGNORE_USER_REGISTRY</envar></term>
<listitem>
<para>
(Windows only)
If this variable is set, options are not read from the user portion of the
Registry (see <xref linkend="options-list"/>).
You might use this to recover if your registry settings get messed up
somehow.
</para>
</listitem>
</varlistentry>
<varlistentry id="SHELL">
<term><envar>SHELL</envar></term>
<listitem>
<para>
The shell that is invoked by the <command>:!</command> command
(see <xref linkend="misc-commands"/>).
</para>
</listitem>
</varlistentry>
</variablelist>
</sect1>
<sect1 id="runhugs">
<title>Standalone programs</title>
<cmdsynopsis>
<command>runhugs</command>
<arg rep="repeat" choice="opt"><replaceable>option</replaceable></arg>
<arg choice="plain"><replaceable>file</replaceable></arg>
</cmdsynopsis>
<para>
The <command>runhugs</command> command is an interpreter for an executable Hugs
script, which must be a file containing a Haskell
<literal>Main</literal> module.
For example, an executable file might contain the lines
<programlisting>
#!/usr/local/bin/runhugs +l
> module Main where
> main = putStr "Hello, World\n"
</programlisting>
When this file is executed, <command>runhugs</command> will invoke
the <literal>main</literal> function.
Any arguments given on the command line will be available through
the <literal>getArgs</literal> action.
</para>
</sect1>
<sect1 id="ffihugs">
<title>Compiling modules that use the Foreign Function Interface</title>
<cmdsynopsis>
<command>ffihugs</command> <arg><option>+G</option></arg>
<arg rep="repeat" choice="opt"><replaceable>option</replaceable></arg>
<arg rep="repeat" choice="opt"><option>+L</option><replaceable>cc-option</replaceable></arg>
<arg choice="plain"><replaceable>file</replaceable></arg>
</cmdsynopsis>
<para>
Suppose you have some C functions in <literal>test.c</literal>
and some ffi declarations for those functions in <literal>Test.hs</literal>
and the code in <literal>test.c</literal> needs to be
compiled with <option>-lm</option>.
To use these with Hugs, you must first use <command>ffihugs</command>
to generate <literal>Test.c</literal>, compile it and link it against
<literal>test.c</literal> with <option>-lm</option> to produce
<literal>Test.so</literal>:
<programlisting>
ffihugs +G +L"test.c" +L"-lm" Test.hs
</programlisting>
(If <literal>Test.hs</literal> depends on other ffi modules,
you'll have to compile them first.)
Now you can run Hugs as normal;
when <literal>Test.hs</literal> is loaded,
Hugs will load <literal>Test.so</literal>.)
<programlisting>
hugs Test.hs
</programlisting>
and then use the imported or exported functions.
</para>
</sect1>
</chapter>
|