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 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="manual.css">
<TITLE>
Expressions
</TITLE>
</HEAD>
<BODY >
<A HREF="manual014.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual016.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<H2 CLASS="section"><A NAME="htoc66">6.7</A> Expressions</H2> <A NAME="s:value-expr"></A>
<A NAME="@manual.kwd8"></A>
<A NAME="@manual.kwd9"></A>
<A NAME="@manual.kwd10"></A>
<A NAME="@manual.kwd11"></A>
<A NAME="@manual.kwd12"></A>
<A NAME="@manual.kwd13"></A>
<A NAME="@manual.kwd14"></A>
<A NAME="@manual.kwd15"></A>
<A NAME="@manual.kwd16"></A>
<A NAME="@manual.kwd17"></A>
<A NAME="@manual.kwd18"></A>
<A NAME="@manual.kwd19"></A>
<A NAME="@manual.kwd20"></A>
<A NAME="@manual.kwd21"></A>
<A NAME="@manual.kwd22"></A>
<A NAME="@manual.kwd23"></A>
<A NAME="@manual.kwd24"></A>
<A NAME="@manual.kwd25"></A>
<A NAME="@manual.kwd26"></A>
<A NAME="@manual.kwd27"></A>
<A NAME="@manual.kwd28"></A>
<A NAME="@manual.kwd29"></A>
<A NAME="@manual.kwd30"></A>
<A NAME="@manual.kwd31"></A><BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<A NAME="expr"></A>
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
<FONT COLOR=maroon><I><a href="manual011.html#value-path"><font color=maroon><TT>value-path</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual013.html#constant"><font color=maroon><TT>constant</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>begin</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>end</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>:</TT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>,</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> { <FONT COLOR=blue><TT>,</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual011.html#constr"><font color=maroon><TT>constr</TT></font></a> <a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>`</TT></FONT><FONT COLOR=maroon><I><a href="manual011.html#tag-name"><font color=maroon><TT>tag-name</TT></font></a> <a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>::</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>[</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> { <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>]</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>[|</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> { <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>|]</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#field"><font color=maroon><I>field</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> { <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#field"><font color=maroon><I>field</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> } <FONT COLOR=blue><TT>}</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>with</TT></FONT> <TT><a href="manual011.html#field"><font color=maroon><I>field</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> { <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#field"><font color=maroon><I>field</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> } <FONT COLOR=blue><TT>}</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> { <FONT COLOR=maroon><I><a href="#argument"><font color=maroon><TT>argument</TT></font></a></I></FONT> }<SUP>+</SUP></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual009.html#prefix-symbol"><font color=maroon><TT>prefix-symbol</TT></font></a> <a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a> <a href="manual011.html#infix-op"><font color=maroon><TT>infix-op</TT></font></a> <a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>.</TT></FONT> <TT><a href="manual011.html#field"><font color=maroon><I>field</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>.</TT></FONT> <TT><a href="manual011.html#field"><font color=maroon><I>field</I></font></a></TT> <FONT COLOR=blue><TT><-</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>.(</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <FONT COLOR=blue><TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>.(</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>)</TT> <TT><-</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>.[</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <FONT COLOR=blue><TT>]</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>.[</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>]</TT> <TT><-</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>if</TT></FONT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>then</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> [ <FONT COLOR=blue><TT>else</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> ]</TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>while</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>do</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>done</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>for</TT></FONT> <FONT COLOR=maroon><TT><a href="manual009.html#ident"><font color=maroon><I>ident</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> ( <FONT COLOR=blue><TT>to</TT></FONT> ∣ <FONT COLOR=blue><TT>downto</TT></FONT> ) <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>do</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <FONT COLOR=blue><TT>done</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>;</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>match</TT></FONT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>with</TT></FONT> <TT><a href="#pattern-matching"><font color=maroon><I>pattern-matching</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>function</TT></FONT> <FONT COLOR=maroon><I><a href="#pattern-matching"><font color=maroon><TT>pattern-matching</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><I><a href="#multiple-matching"><font color=maroon><TT>multiple-matching</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>try</TT></FONT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>with</TT></FONT> <TT><a href="#pattern-matching"><font color=maroon><I>pattern-matching</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>let</TT></FONT> [<FONT COLOR=blue><TT>rec</TT></FONT>] <FONT COLOR=maroon><I><a href="#let-binding"><font color=maroon><TT>let-binding</TT></font></a></I></FONT> { <FONT COLOR=blue><TT>and</TT></FONT> <FONT COLOR=maroon><I><a href="#let-binding"><font color=maroon><TT>let-binding</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>in</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>new</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#class-path"><font color=maroon><TT>class-path</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>object</TT></FONT> [<FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="manual014.html#pattern"><font color=maroon><TT>pattern</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>)</TT></FONT>] { <FONT COLOR=maroon><I><a href="manual017.html#class-field"><font color=maroon><TT>class-field</TT></font></a></I></FONT> } <FONT COLOR=blue><TT>end</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT> <FONT COLOR=blue><TT>#</TT></FONT> <TT><a href="manual011.html#method-name"><font color=maroon><I>method-name</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual011.html#inst-var-name"><font color=maroon><TT>inst-var-name</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</I></font></a></TT> <FONT COLOR=blue><TT><-</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>:></TT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> <TT>:</TT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT> <TT>:></TT> <FONT COLOR=maroon><TT><a href="manual012.html#typexpr"><font color=maroon><I>typexpr</I></font></a></TT></FONT> <TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>{<</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> { <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#inst-var-name"><font color=maroon><I>inst-var-name</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT> } <FONT COLOR=blue><TT>>}</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>assert</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>lazy</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="argument"></A>
<FONT COLOR=maroon><I><TT>argument</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
<FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>~</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#label-name"><font color=maroon><TT>label-name</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>~</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#label-name"><font color=maroon><I>label-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>?</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#label-name"><font color=maroon><TT>label-name</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>?</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#label-name"><font color=maroon><I>label-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="pattern-matching"></A>
<FONT COLOR=maroon><I><TT>pattern-matching</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
[ <FONT COLOR=blue><TT>|</TT></FONT> ] <FONT COLOR=maroon><I><a href="manual014.html#pattern"><font color=maroon><TT>pattern</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>when</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT>
{ <FONT COLOR=blue><TT>|</TT></FONT> <FONT COLOR=maroon><I><a href="manual014.html#pattern"><font color=maroon><TT>pattern</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>when</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT> }</TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="multiple-matching"></A>
<FONT COLOR=maroon><I><TT>multiple-matching</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
{ <FONT COLOR=maroon><I><a href="#parameter"><font color=maroon><TT>parameter</TT></font></a></I></FONT> }<SUP>+</SUP> [<FONT COLOR=blue><TT>when</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="let-binding"></A>
<FONT COLOR=maroon><I><TT>let-binding</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
<FONT COLOR=maroon><TT><a href="manual014.html#pattern"><font color=maroon><I>pattern</I></font></a></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><a href="#expr"><font color=maroon><I>expr</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=maroon><I><a href="manual011.html#value-name"><font color=maroon><TT>value-name</TT></font></a></I></FONT> { <FONT COLOR=maroon><I><a href="#parameter"><font color=maroon><TT>parameter</TT></font></a></I></FONT> } [<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP>
<A NAME="parameter"></A>
<FONT COLOR=maroon><I><TT>parameter</TT></I></FONT></TD>
<TD ALIGN=right NOWRAP>::=</TD>
<TD ALIGN=left NOWRAP>
<FONT COLOR=maroon><I><a href="manual014.html#pattern"><font color=maroon><TT>pattern</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>~</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#label-name"><font color=maroon><TT>label-name</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>~</TT> <TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#label-name"><font color=maroon><TT>label-name</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>~</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#label-name"><font color=maroon><I>label-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="manual014.html#pattern"><font color=maroon><I>pattern</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>?</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#label-name"><font color=maroon><TT>label-name</TT></font></a></I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>?</TT> <TT>(</TT></FONT> <FONT COLOR=maroon><I><a href="manual011.html#label-name"><font color=maroon><TT>label-name</TT></font></a></I></FONT> [<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT>] [<FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>)</TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>?</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#label-name"><font color=maroon><I>label-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><a href="manual014.html#pattern"><font color=maroon><I>pattern</I></font></a></TT></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=right NOWRAP>∣</TD>
<TD ALIGN=left NOWRAP> <FONT COLOR=blue><TT>?</TT></FONT> <FONT COLOR=maroon><TT><a href="manual011.html#label-name"><font color=maroon><I>label-name</I></font></a></TT> <FONT COLOR=blue><TT>:</TT> <TT>(</TT></FONT> <TT><a href="manual014.html#pattern"><font color=maroon><I>pattern</I></font></a></TT></FONT> [<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><a href="manual012.html#typexpr"><font color=maroon><TT>typexpr</TT></font></a></I></FONT>] [<FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><a href="#expr"><font color=maroon><TT>expr</TT></font></a></I></FONT>] <FONT COLOR=blue><TT>)</TT></FONT></TD>
</TR></TABLE></DIV><BR>
<BR>
The table below shows the relative precedences and associativity of
operators and non-closed constructions. The constructions with higher
precedence come first. For infix and prefix symbols, we write
“<TT>*</TT>...” to mean “any symbol starting with <TT>*</TT>”.
<A NAME="@manual.kwd32"></A><A NAME="@manual.kwd33"></A><A NAME="@manual.kwd34"></A><A NAME="@manual.kwd35"></A><A NAME="@manual.kwd36"></A><A NAME="@manual.kwd37"></A><A NAME="@manual.kwd38"></A><BR>
<BR>
<DIV CLASS="center"><TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 WIDTH="80%">
<TR><TD ALIGN=center NOWRAP><B>Construction or operator</B></TD>
<TD ALIGN=center NOWRAP><B>Associativity</B></TD>
</TR>
<TR><TD ALIGN=left NOWRAP>
prefix-symbol</TD>
<TD ALIGN=left NOWRAP>–</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>. .( .[</TT></TD>
<TD ALIGN=left NOWRAP>–</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>function application, constructor application, <TT>assert</TT>, <TT>lazy</TT></TD>
<TD ALIGN=left NOWRAP>left</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>- -.</TT> (prefix)</TD>
<TD ALIGN=left NOWRAP>–</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>**</TT>...<TT> <span style="background-color:yellow; color:red">lsl lsr asr</span></TT></TD>
<TD ALIGN=left NOWRAP>right</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>*</TT>...<TT> /</TT>...<TT> %</TT>...<TT> mod <span style="background-color:yellow; color:red">land lor lxor</span></TT></TD>
<TD ALIGN=left NOWRAP>left</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>+</TT>...<TT> -</TT>...</TD>
<TD ALIGN=left NOWRAP>left</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>::</TT></TD>
<TD ALIGN=left NOWRAP>right</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>@</TT>...<TT> ^</TT>...</TD>
<TD ALIGN=left NOWRAP>right</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>comparisons (<TT>= == < </TT> etc.), all other infix symbols</TD>
<TD ALIGN=left NOWRAP>left</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>& &&</TT></TD>
<TD ALIGN=left NOWRAP>left</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>or ||</TT></TD>
<TD ALIGN=left NOWRAP>left</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>,</TT></TD>
<TD ALIGN=left NOWRAP>–</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT><- :=</TT></TD>
<TD ALIGN=left NOWRAP>right</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>if</TT></TD>
<TD ALIGN=left NOWRAP>–</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>;</TT></TD>
<TD ALIGN=left NOWRAP>right</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>let match fun function try</TT></TD>
<TD ALIGN=left NOWRAP>–</TD>
</TR></TABLE></DIV><BR>
<BR>
<H3 CLASS="subsection"><A NAME="htoc67">6.7.1</A> Basic expressions</H3>
<H4 CLASS="subsubsection">Constants</H4>
Expressions consisting in a constant evaluate to this constant.<BR>
<BR>
<H4 CLASS="subsubsection">Value paths</H4> <A NAME="expr:var"></A>
Expressions consisting in an access path evaluate to the value bound to
this path in the current evaluation environment. The path can
be either a value name or an access path to a value component of a module.<BR>
<BR>
<H4 CLASS="subsubsection">Parenthesized expressions</H4>
<A NAME="@manual.kwd39"></A>
<A NAME="@manual.kwd40"></A>
The expressions <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>expr</I></TT></FONT> <TT>)</TT></FONT> and <FONT COLOR=blue><TT>begin</TT> <FONT COLOR=maroon><TT><I>expr</I></TT></FONT> <TT>end</TT></FONT> have the same
value as <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. Both constructs are semantically equivalent, but it
is good style to use <FONT COLOR=blue><TT>begin</TT></FONT> … <FONT COLOR=blue><TT>end</TT></FONT> inside control structures:
<PRE>
if ... then begin ... ; ... end else begin ... ; ... end
</PRE>
and <FONT COLOR=blue><TT>(</TT></FONT> … <FONT COLOR=blue><TT>)</TT></FONT> for the other grouping situations.<BR>
<BR>
Parenthesized expressions can contain a type constraint, as in <FONT COLOR=blue><TT>(</TT>
<FONT COLOR=maroon><TT><I>expr</I></TT></FONT> <TT>:</TT> <FONT COLOR=maroon><TT><I>type</I></TT></FONT> <TT>)</TT></FONT>. This constraint forces the type of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> to be
compatible with <FONT COLOR=maroon><I><TT>type</TT></I></FONT>.<BR>
<BR>
Parenthesized expressions can also contain coercions <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> [<FONT COLOR=blue><TT>:</TT></FONT> <FONT COLOR=maroon><I><TT>type</TT></I></FONT>] <FONT COLOR=blue><TT>:></TT> <TT><FONT COLOR=maroon><I>type</I></FONT>)</TT></FONT> (see subsection <A HREF="#s:objects">6.7.5</A> below).<BR>
<BR>
<H4 CLASS="subsubsection">Function application</H4>
Function application is denoted by juxtaposition of (possibly labeled)
expressions. The expression <FONT COLOR=maroon><I><TT>expr</TT> <TT>argument</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>argument</TT></FONT><SUB>n</SUB></I>
evaluates the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> and those appearing in <FONT COLOR=maroon><I><TT>argument</TT></I></FONT><SUB>1</SUB>
to <I><FONT COLOR=maroon><TT>argument</TT></FONT><SUB>n</SUB></I>. The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> must evaluate to a
functional value <FONT COLOR=maroon><I><TT>f</TT></I></FONT>, which is then applied to the values of
<FONT COLOR=maroon><I><TT>argument</TT></I></FONT><SUB>1</SUB>, …, <I><FONT COLOR=maroon><TT>argument</TT></FONT><SUB>n</SUB></I>.<BR>
<BR>
The order in which the expressions <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, <FONT COLOR=maroon><I><TT>argument</TT></I></FONT><SUB>1</SUB>, …,
<I><FONT COLOR=maroon><TT>argument</TT></FONT><SUB>n</SUB></I> are evaluated is not specified.<BR>
<BR>
Arguments and parameters are matched according to their respective
labels. Argument order is irrelevant, except among arguments with the
same label, or no label.<BR>
<BR>
If a parameter is specified as optional (label prefixed by <TT>?</TT>) in the
type of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, the corresponding argument will be automatically
wrapped with the constructor <TT>Some</TT>, except if the argument itself is
also prefixed by <TT>?</TT>, in which case it is passed as is.
If a non-labeled argument is passed, and its corresponding parameter
is preceded by one or several optional parameters, then these
parameters are <EM>defaulted</EM>, <EM>i.e.</EM> the value <TT>None</TT> will be
passed for them.
All other missing parameters (without corresponding argument), both
optional and non-optional, will be kept, and the result of the
function will still be a function of these missing parameters to the
body of <FONT COLOR=maroon><I><TT>f</TT></I></FONT>.<BR>
<BR>
As a special case, if the function has a known arity, all the
arguments are unlabeled, and their number matches the number of
non-optional parameters, then labels are ignored and non-optional
parameters are matched in their definition order. Optional arguments
are defaulted.<BR>
<BR>
In all cases but exact match of order and labels, without optional
parameters, the function type should be known at the application
point. This can be ensured by adding a type constraint. Principality
of the derivation can be checked in the <TT>-principal</TT> mode.<BR>
<BR>
<H4 CLASS="subsubsection">Function definition</H4>
Two syntactic forms are provided to define functions. The first form
is introduced by the keyword <TT>function</TT>:
<A NAME="@manual.kwd41"></A><BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>function</TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>pattern</I></FONT><SUB>1</SUB></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>expr</I></FONT><SUB>1</SUB></TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP>…</TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>pattern</FONT><SUB>n</SUB></I></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>expr</FONT><SUB>n</SUB></I></TD>
</TR></TABLE></DIV>
This expression evaluates to a functional value with one argument.
When this function is applied to a value <I>v</I>, this value is
matched against each pattern <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I>.
If one of these matchings succeeds, that is, if the value <I>v</I>
matches the pattern <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>i</SUB></I> for some <I>i</I>,
then the expression <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> associated to the selected pattern
is evaluated, and its value becomes the value of the function
application. The evaluation of <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> takes place in an
environment enriched by the bindings performed during the matching.<BR>
<BR>
If several patterns match the argument <I>v</I>, the one that occurs
first in the function definition is selected. If none of the patterns
matches the argument, the exception <TT>Match_failure</TT> is raised.
<A NAME="@manual0"></A><BR>
<BR>
<BR>
<BR>
<BR>
The other form of function definition is introduced by the keyword <TT>fun</TT>:
<A NAME="@manual.kwd42"></A>
<DIV CLASS="center">
<FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><I><TT>parameter</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>parameter</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
This expression is equivalent to:
<DIV CLASS="center">
<FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><I><TT>parameter</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-></TT></FONT> … <FONT COLOR=blue><TT>fun</TT></FONT> <I><FONT COLOR=maroon><TT>parameter</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
Functions of the form <FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><TT><I>optlabel</I></TT> <FONT COLOR=blue><TT>(</TT></FONT> <TT><I>pattern</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>expr</I></TT></FONT><SUB>0</SUB> <FONT COLOR=blue><TT>)</TT> <TT>-></TT></FONT>
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT> are equivalent to
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP>
<FONT COLOR=blue><TT>fun</TT></FONT> <FONT COLOR=maroon><I><TT>optlabel</TT> <TT>x</TT></I> <FONT COLOR=blue><TT>-></TT>
<TT>let</TT></FONT> <TT><I>pattern</I></TT> <FONT COLOR=blue><TT>=</TT>
<TT>match</TT></FONT> <TT><I>x</I></TT> <FONT COLOR=blue><TT>with</TT> <TT>Some</TT></FONT> <TT><I>x</I></TT> <FONT COLOR=blue><TT>-></TT></FONT> <TT><I>x</I></TT> <FONT COLOR=blue><TT>|</TT> <TT>None</TT> <TT>-></TT></FONT> <TT><I>expr</I></TT></FONT><SUB>0</SUB>
<FONT COLOR=blue><TT>in</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT></TD>
</TR></TABLE></DIV>
where <FONT COLOR=maroon><I><TT>x</TT></I></FONT> is a fresh variable. When <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>0</SUB> will be evaluated is left
unspecified.<BR>
<BR>
After these two transformations, expressions are of the form
<DIV CLASS="center">
<FONT COLOR=blue><TT>fun</TT></FONT> [<FONT COLOR=maroon><I><TT>label</TT></I></FONT><SUB>1</SUB>] <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-></TT></FONT> … <FONT COLOR=blue><TT>fun</TT></FONT> [<I><FONT COLOR=maroon><TT>label</TT></FONT><SUB>n</SUB></I>] <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
If we ignore labels, which will only be meaningful at function
application, this is equivalent to
<DIV CLASS="center">
<FONT COLOR=blue><TT>function</TT></FONT> <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>-></TT></FONT> … <FONT COLOR=blue><TT>function</TT></FONT> <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
That is, the <TT>fun</TT> expression above evaluates to a curried function
with <I>n</I> arguments: after applying this function <I>n</I> times to the
values <I>v</I><SUB>1</SUB> ... <I>v<SUB>m</SUB></I>, the values will be matched
in parallel against the patterns <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I>.
If the matching succeeds, the function returns the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> in
an environment enriched by the bindings performed during the matchings.
If the matching fails, the exception <TT>Match_failure</TT> is raised.<BR>
<BR>
<H4 CLASS="subsubsection">Guards in pattern-matchings</H4>
<A NAME="@manual.kwd43"></A>
Cases of a pattern matching (in the <TT>function</TT>, <TT>fun</TT>, <TT>match</TT> and
<TT>try</TT> constructs) can include guard expressions, which are
arbitrary boolean expressions that must evaluate to <TT>true</TT> for the
match case to be selected. Guards occur just before the <TT>-></TT> token and
are introduced by the <TT>when</TT> keyword:<BR>
<BR>
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>function</TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>pattern</I></FONT><SUB>1</SUB> [<FONT COLOR=blue><TT>when</TT></FONT> <FONT COLOR=maroon><I>cond</I></FONT><SUB>1</SUB>]</TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>expr</I></FONT><SUB>1</SUB></TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP>…</TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>pattern</FONT><SUB>n</SUB></I> [<FONT COLOR=blue><TT>when</TT></FONT> <I><FONT COLOR=maroon>cond</FONT><SUB>n</SUB></I>]</TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>expr</FONT><SUB>n</SUB></I></TD>
</TR></TABLE></DIV><BR>
<BR>
Matching proceeds as described before, except that if the value
matches some pattern <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>i</SUB></I> which has a guard <I><FONT COLOR=maroon><TT>cond</TT></FONT><SUB>i</SUB></I>, then the
expression <I><FONT COLOR=maroon><TT>cond</TT></FONT><SUB>i</SUB></I> is evaluated (in an environment enriched by the
bindings performed during matching). If <I><FONT COLOR=maroon><TT>cond</TT></FONT><SUB>i</SUB></I> evaluates to <TT>true</TT>,
then <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> is evaluated and its value returned as the result of the
matching, as usual. But if <I><FONT COLOR=maroon><TT>cond</TT></FONT><SUB>i</SUB></I> evaluates to <TT>false</TT>, the matching
is resumed against the patterns following <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>i</SUB></I>.<BR>
<BR>
<H4 CLASS="subsubsection">Local definitions</H4> <A NAME="s:localdef"></A>
<A NAME="@manual.kwd44"></A>
The <TT>let</TT> and <TT>let rec</TT> constructs bind value names locally.
The construct
<DIV CLASS="center">
<FONT COLOR=blue><TT>let</TT></FONT> <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> … <FONT COLOR=blue><TT>and</TT></FONT> <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>in</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
evaluates <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> in some unspecified order, then matches
their values against the patterns <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I>. If the
matchings succeed, <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> is evaluated in the environment enriched by
the bindings performed during matching, and the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> is
returned as the value of the whole <TT>let</TT> expression. If one of the
matchings fails, the exception <TT>Match_failure</TT> is raised.
<A NAME="@manual1"></A><BR>
<BR>
An alternate syntax is provided to bind variables to functional
values: instead of writing
<DIV CLASS="center">
<FONT COLOR=blue><TT>let</TT></FONT> <FONT COLOR=maroon><TT><I>ident</I></TT> <FONT COLOR=blue><TT>=</TT> <TT>fun</TT></FONT> <TT><I>parameter</I></TT></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>parameter</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>-></TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
in a <TT>let</TT> expression, one may instead write
<DIV CLASS="center">
<FONT COLOR=blue><TT>let</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT> <TT>parameter</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>parameter</TT></FONT><SUB>m</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV><BR>
<BR>
<BR>
Recursive definitions of names are introduced by <TT>let rec</TT>:
<DIV CLASS="center">
<FONT COLOR=blue><TT>let</TT> <TT>rec</TT></FONT> <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>and</TT></FONT> … <FONT COLOR=blue><TT>and</TT></FONT> <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I>
<FONT COLOR=blue><TT>in</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
The only difference with the <TT>let</TT> construct described above is
that the bindings of names to values performed by the
pattern-matching are considered already performed when the expressions
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> are evaluated. That is, the expressions <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>
to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> can reference identifiers that are bound by one of the
patterns <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB>, …, <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I>, and expect them to have the
same value as in <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, the body of the <TT>let rec</TT> construct.<BR>
<BR>
The recursive definition is guaranteed to behave as described above if
the expressions <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> are function definitions
(<FONT COLOR=blue><TT>fun</TT></FONT> … or <FONT COLOR=blue><TT>function</TT></FONT> …), and the patterns <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB>
… <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I> are just value names, as in:
<DIV CLASS="center">
<FONT COLOR=blue><TT>let</TT> <TT>rec</TT></FONT> <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT> <TT>fun</TT></FONT> …
<FONT COLOR=blue><TT>and</TT></FONT> …
<FONT COLOR=blue><TT>and</TT></FONT> <I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT> <TT>fun</TT></FONT> …
<FONT COLOR=blue><TT>in</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
</DIV>
This defines <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>name</TT></FONT><SUB>n</SUB></I> as mutually recursive functions
local to <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. <BR>
<BR>
The behavior of other forms of <TT>let rec</TT> definitions is
implementation-dependent. The current implementation also supports
a certain class of recursive definitions of non-functional values,
as explained in section <A HREF="manual021.html#s:letrecvalues">7.3</A>.<BR>
<BR>
<H3 CLASS="subsection"><A NAME="htoc68">6.7.2</A> Control structures</H3>
<H4 CLASS="subsubsection">Sequence</H4>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> evaluates <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> first, then
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>, and returns the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>.<BR>
<BR>
<H4 CLASS="subsubsection">Conditional</H4>
<A NAME="@manual.kwd45"></A>
The expression <FONT COLOR=blue><TT>if</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>then</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>else</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> evaluates to
the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> if <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> evaluates to the boolean <FONT COLOR=blue><TT>true</TT></FONT>,
and to the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> if <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> evaluates to the boolean
<FONT COLOR=blue><TT>false</TT></FONT>.<BR>
<BR>
The <FONT COLOR=blue><TT>else</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> part can be omitted, in which case it defaults to
<FONT COLOR=blue><TT>else</TT> <TT>()</TT></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Case expression</H4><A NAME="@manual.kwd46"></A>
The expression
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>match</TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>expr</I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>with</TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>pattern</I></FONT><SUB>1</SUB></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>expr</I></FONT><SUB>1</SUB></TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP>…</TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>pattern</FONT><SUB>n</SUB></I></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>expr</FONT><SUB>n</SUB></I></TD>
</TR></TABLE></DIV>
matches the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> against the patterns <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> to
<I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I>. If the matching against <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>i</SUB></I> succeeds, the
associated expression <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> is evaluated, and its value becomes the
value of the whole <FONT COLOR=blue><TT>match</TT></FONT> expression. The evaluation of
<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> takes place in an environment enriched by the bindings
performed during matching. If several patterns match the value of
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, the one that occurs first in the <FONT COLOR=blue><TT>match</TT></FONT> expression is
selected. If none of the patterns match the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, the
exception <FONT COLOR=blue><TT>Match_failure</TT></FONT> is raised.
<A NAME="@manual2"></A><BR>
<BR>
<H4 CLASS="subsubsection">Boolean operators</H4>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>&&</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> evaluates to <FONT COLOR=blue><TT>true</TT></FONT> if both
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> and <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> evaluate to <FONT COLOR=blue><TT>true</TT></FONT>; otherwise, it evaluates to
<FONT COLOR=blue><TT>false</TT></FONT>. The first component, <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>, is evaluated first. The
second component, <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>, is not evaluated if the first component
evaluates to <FONT COLOR=blue><TT>false</TT></FONT>. Hence, the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>&&</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> behaves
exactly as
<DIV CLASS="center">
<FONT COLOR=blue><TT>if</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>then</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>else</TT> <TT>false</TT></FONT>.
</DIV><BR>
<BR>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>||</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> evaluates to <FONT COLOR=blue><TT>true</TT></FONT> if one of
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> and <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> evaluates to <FONT COLOR=blue><TT>true</TT></FONT>; otherwise, it evaluates to
<FONT COLOR=blue><TT>false</TT></FONT>. The first component, <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>, is evaluated first. The
second component, <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>, is not evaluated if the first component
evaluates to <FONT COLOR=blue><TT>true</TT></FONT>. Hence, the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>||</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> behaves
exactly as
<DIV CLASS="center">
<FONT COLOR=blue><TT>if</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>then</TT> <TT>true</TT> <TT>else</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>.
</DIV><BR>
<BR>
<A NAME="@manual.kwd47"></A>
The boolean operator <FONT COLOR=blue><TT>&</TT></FONT> is synonymous for <FONT COLOR=blue><TT>&&</TT></FONT>. The boolean operator
<FONT COLOR=blue><TT>or</TT></FONT> is synonymous for <FONT COLOR=blue><TT>||</TT></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Loops</H4>
<A NAME="@manual.kwd48"></A>
The expression <FONT COLOR=blue><TT>while</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>do</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>done</TT></FONT> repeatedly
evaluates <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> while <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> evaluates to <FONT COLOR=blue><TT>true</TT></FONT>. The loop
condition <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> is evaluated and tested at the beginning of each
iteration. The whole <FONT COLOR=blue><TT>while</TT></FONT> … <FONT COLOR=blue><TT>done</TT></FONT> expression evaluates to
the unit value <FONT COLOR=blue><TT>()</TT></FONT>.<BR>
<BR>
<A NAME="@manual.kwd49"></A>
The expression <FONT COLOR=blue><TT>for</TT></FONT> <FONT COLOR=maroon><TT><I>name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>expr</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>to</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>do</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> <FONT COLOR=blue><TT>done</TT></FONT>
first evaluates the expressions <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> and <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> (the boundaries)
into integer values <I>n</I> and <I>p</I>. Then, the loop body <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> is
repeatedly evaluated in an environment where <FONT COLOR=maroon><I><TT>name</TT></I></FONT> is successively
bound to the values
<I>n</I>, <I>n</I>+1, ..., <I>p</I>−1, <I>p</I>.
The loop body is never evaluated if <I>n</I> > <I>p</I>.<BR>
<BR>
The expression <FONT COLOR=blue><TT>for</TT></FONT> <FONT COLOR=maroon><TT><I>name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>expr</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>downto</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>do</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> <FONT COLOR=blue><TT>done</TT></FONT>
evaluates similarly, except that <FONT COLOR=maroon><I><TT>name</TT></I></FONT> is successively bound to the values
<I>n</I>, <I>n</I>−1, ..., <I>p</I>+1, <I>p</I>.
The loop body is never evaluated if <I>n</I> < <I>p</I>.<BR>
<BR>
In both cases, the whole <FONT COLOR=blue><TT>for</TT></FONT> expression evaluates to the unit
value <FONT COLOR=blue><TT>()</TT></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Exception handling</H4>
<A NAME="@manual.kwd50"></A>
The expression
<DIV CLASS="center"><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>try </TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>expr</I></FONT></TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>with</TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>pattern</I></FONT><SUB>1</SUB></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=maroon><I>expr</I></FONT><SUB>1</SUB></TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP>…</TD>
</TR>
<TR><TD ALIGN=right NOWRAP><FONT COLOR=blue><TT>|</TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>pattern</FONT><SUB>n</SUB></I></TD>
<TD ALIGN=left NOWRAP><FONT COLOR=blue><TT>-></TT></FONT></TD>
<TD ALIGN=left NOWRAP><I><FONT COLOR=maroon>expr</FONT><SUB>n</SUB></I></TD>
</TR></TABLE></DIV>
evaluates the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> and returns its value if the
evaluation of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> does not raise any exception. If the evaluation
of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> raises an exception, the exception value is matched against
the patterns <FONT COLOR=maroon><I><TT>pattern</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>n</SUB></I>. If the matching against
<I><FONT COLOR=maroon><TT>pattern</TT></FONT><SUB>i</SUB></I> succeeds, the associated expression <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> is evaluated,
and its value becomes the value of the whole <FONT COLOR=blue><TT>try</TT></FONT> expression. The
evaluation of <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> takes place in an environment enriched by the
bindings performed during matching. If several patterns match the value of
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, the one that occurs first in the <FONT COLOR=blue><TT>try</TT></FONT> expression is
selected. If none of the patterns matches the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, the
exception value is raised again, thereby transparently “passing
through” the <FONT COLOR=blue><TT>try</TT></FONT> construct.<BR>
<BR>
<H3 CLASS="subsection"><A NAME="htoc69">6.7.3</A> Operations on data structures</H3>
<H4 CLASS="subsubsection">Products</H4>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>,</TT></FONT> … <FONT COLOR=blue><TT>,</TT></FONT> <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> evaluates to the
<I>n</I>-tuple of the values of expressions <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I>. The
evaluation order for the subexpressions is not specified.<BR>
<BR>
<H4 CLASS="subsubsection">Variants</H4>
The expression <FONT COLOR=maroon><I><TT>constr</TT> <TT>expr</TT></I></FONT> evaluates to the variant value whose
constructor is <FONT COLOR=maroon><I><TT>constr</TT></I></FONT>, and whose argument is the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>.<BR>
<BR>
For lists, some syntactic sugar is provided. The expression
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>::</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> stands for the constructor <FONT COLOR=blue><TT>(</TT> <TT>::</TT> <TT>)</TT></FONT>
applied to the argument <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>,</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>)</TT></FONT>, and therefore
evaluates to the list whose head is the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> and whose tail
is the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>. The expression <FONT COLOR=blue><TT>[</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>;</TT></FONT> … <FONT COLOR=blue><TT>;</TT></FONT>
<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>]</TT></FONT> is equivalent to <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>::</TT></FONT> … <FONT COLOR=blue><TT>::</TT></FONT> <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>::</TT>
<TT>[]</TT></FONT>, and therefore evaluates to the list whose elements are the
values of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I>.<BR>
<BR>
<H4 CLASS="subsubsection">Polymorphic variants</H4>
The expression <FONT COLOR=blue><TT>`</TT></FONT><FONT COLOR=maroon><I><TT>tag-name</TT> <TT>expr</TT></I></FONT> evaluates to the variant value whose
tag is <FONT COLOR=maroon><I><TT>tag-name</TT></I></FONT>, and whose argument is the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Records</H4>
The expression <FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>;</TT></FONT> … <FONT COLOR=blue><TT>;</TT></FONT> <I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT>
<I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT> evaluates to the record value
<FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>v</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>;</TT></FONT> … <FONT COLOR=blue><TT>;</TT></FONT> <I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> <I><FONT COLOR=maroon><TT>v</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT>,
where <I><FONT COLOR=maroon><TT>v</TT></FONT><SUB>i</SUB></I> is the value of <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>i</SUB></I> for <I>i</I> = 1,… , <I>n</I>.
The fields <FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>n</SUB></I> must all belong to the same record
types; all fields belonging to this record type must appear exactly
once in the record expression, though they can appear in any
order. The order in which <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> are evaluated is not
specified.<BR>
<BR>
The expression
<FONT COLOR=blue><TT>{</TT></FONT> <FONT COLOR=maroon><TT><I>expr</I></TT> <FONT COLOR=blue><TT>with</TT></FONT> <TT><I>field</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>=</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>;</TT></FONT> … <FONT COLOR=blue><TT>;</TT></FONT> <I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>=</TT></FONT> <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>}</TT></FONT>
builds a fresh record with fields <FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>n</SUB></I> equal to
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I>, and all other fields having the same value as
in the record <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>. In other terms, it returns a shallow copy of
the record <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>, except for the fields <FONT COLOR=maroon><I><TT>field</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>field</TT></FONT><SUB>n</SUB></I>,
which are initialized to <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> … <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I>.<BR>
<BR>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.</TT></FONT> <FONT COLOR=maroon><I><TT>field</TT></I></FONT> evaluates <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to a record
value, and returns the value associated to <FONT COLOR=maroon><I><TT>field</TT></I></FONT> in this record
value.<BR>
<BR>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.</TT></FONT> <FONT COLOR=maroon><TT><I>field</I></TT> <FONT COLOR=blue><TT><-</TT></FONT> <TT><I>expr</I></TT></FONT><SUB>2</SUB> evaluates <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to a record
value, which is then modified in-place by replacing the value
associated to <FONT COLOR=maroon><I><TT>field</TT></I></FONT> in this record by the value of
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>. This operation is permitted only if <FONT COLOR=maroon><I><TT>field</TT></I></FONT> has been
declared <FONT COLOR=blue><TT>mutable</TT></FONT> in the definition of the record type. The whole
expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.</TT></FONT> <FONT COLOR=maroon><TT><I>field</I></TT> <FONT COLOR=blue><TT><-</TT></FONT> <TT><I>expr</I></TT></FONT><SUB>2</SUB> evaluates to the unit value
<FONT COLOR=blue><TT>()</TT></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Arrays</H4>
The expression <FONT COLOR=blue><TT>[|</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>;</TT></FONT> … <FONT COLOR=blue><TT>;</TT></FONT> <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> <FONT COLOR=blue><TT>|]</TT></FONT> evaluates to
a <I>n</I>-element array, whose elements are initialized with the values of
<FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> to <I><FONT COLOR=maroon><TT>expr</TT></FONT><SUB>n</SUB></I> respectively. The order in which these
expressions are evaluated is unspecified.<BR>
<BR>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.(</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>)</TT></FONT> returns the value of element
number <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> in the array denoted by <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>. The first element
has number 0; the last element has number <I>n</I>−1, where <I>n</I> is the
size of the array. The exception <TT>Invalid_argument</TT> is raised if the
access is out of bounds.<BR>
<BR>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.(</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>)</TT> <TT><-</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> modifies in-place
the array denoted by <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>, replacing element number <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> by
the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB>. The exception <TT>Invalid_argument</TT> is raised if
the access is out of bounds. The value of the whole expression is <FONT COLOR=blue><TT>()</TT></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Strings</H4>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.[</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>]</TT></FONT> returns the value of character
number <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> in the string denoted by <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>. The first character
has number 0; the last character has number <I>n</I>−1, where <I>n</I> is the
length of the string. The exception <TT>Invalid_argument</TT> is raised if the
access is out of bounds.<BR>
<BR>
The expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>.[</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>]</TT> <TT><-</TT></FONT> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB> modifies in-place
the string denoted by <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB>, replacing character number <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB> by
the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>3</SUB>. The exception <TT>Invalid_argument</TT> is raised if
the access is out of bounds. The value of the whole expression is <FONT COLOR=blue><TT>()</TT></FONT>.<BR>
<BR>
<H3 CLASS="subsection"><A NAME="htoc70">6.7.4</A> Operators</H3>
Symbols from the class <FONT COLOR=blue><TT>infix-symbols</TT></FONT>, as well as the keywords
<TT>*</TT>, <TT>=</TT>, <TT>or</TT> and <TT>&</TT>, can appear in infix position (between two
expressions). Symbols from the class <FONT COLOR=blue><TT>prefix-symbols</TT></FONT>
can appear in prefix position (in front of an expression).<BR>
<BR>
Infix and prefix symbols do not have a fixed meaning: they are simply
interpreted as applications of functions bound to the names
corresponding to the symbols. The expression <FONT COLOR=maroon><I><TT>prefix-symbol</TT> <TT>expr</TT></I></FONT> is
interpreted as the application <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><I>prefix-symbol</I></TT> <FONT COLOR=blue><TT>)</TT></FONT>
<TT><I>expr</I></TT></FONT>. Similarly, the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>1</SUB> <FONT COLOR=maroon><I><TT>infix-symbol</TT> <TT>expr</TT></I></FONT><SUB>2</SUB> is
interpreted as the application <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><I>infix-symbol</I></TT> <FONT COLOR=blue><TT>)</TT></FONT> <TT><I>expr</I></TT></FONT><SUB>1</SUB> <FONT COLOR=maroon><I><TT>expr</TT></I></FONT><SUB>2</SUB>.<BR>
<BR>
The table below lists the symbols defined in the initial environment
and their initial meaning. (See the description of the standard
library module <TT>Pervasive</TT> in chapter <A HREF="manual034.html#c:stdlib">20</A> for more
details). Their meaning may be changed at any time using
<FONT COLOR=blue><TT>let</TT></FONT> <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><I>infix-op</I></TT> <FONT COLOR=blue><TT>)</TT></FONT> <TT><I>name</I></TT></FONT><SUB>1</SUB> <FONT COLOR=maroon><I><TT>name</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>=</TT></FONT> …<BR>
<BR>
<DIV CLASS="center"><TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 WIDTH="80%">
<TR><TD ALIGN=center NOWRAP><B>Operator</B></TD>
<TD ALIGN=center NOWRAP><B>Initial meaning</B></TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP>
<TT>+</TT></TD>
<TD VALIGN=top ALIGN=left>Integer addition.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>-</TT> (infix)</TD>
<TD VALIGN=top ALIGN=left>Integer subtraction.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>-</TT> (prefix)</TD>
<TD VALIGN=top ALIGN=left>Integer negation.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>*</TT></TD>
<TD VALIGN=top ALIGN=left>Integer multiplication.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>/</TT></TD>
<TD VALIGN=top ALIGN=left>Integer division.
Raise <TT>Division_by_zero</TT> if second argument is zero.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>mod</TT></TD>
<TD VALIGN=top ALIGN=left>Integer modulus. Raise
<TT>Division_by_zero</TT> if second argument is zero.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>land</TT></TD>
<TD VALIGN=top ALIGN=left>Bitwise logical “and” on integers.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>lor</TT></TD>
<TD VALIGN=top ALIGN=left>Bitwise logical “or” on integers.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>lxor</TT></TD>
<TD VALIGN=top ALIGN=left>Bitwise logical “exclusive or” on integers.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>lsl</TT></TD>
<TD VALIGN=top ALIGN=left>Bitwise logical shift left on integers.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>lsr</TT></TD>
<TD VALIGN=top ALIGN=left>Bitwise logical shift right on integers.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>asr</TT></TD>
<TD VALIGN=top ALIGN=left>Bitwise arithmetic shift right on integers.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>+.</TT></TD>
<TD VALIGN=top ALIGN=left>Floating-point addition.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>-.</TT> (infix)</TD>
<TD VALIGN=top ALIGN=left>Floating-point subtraction.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>-.</TT> (prefix)</TD>
<TD VALIGN=top ALIGN=left>Floating-point negation.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>*.</TT></TD>
<TD VALIGN=top ALIGN=left>Floating-point multiplication.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>/.</TT></TD>
<TD VALIGN=top ALIGN=left>Floating-point division.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>**</TT></TD>
<TD VALIGN=top ALIGN=left>Floating-point exponentiation.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>@</TT> </TD>
<TD VALIGN=top ALIGN=left>List concatenation.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>^</TT> </TD>
<TD VALIGN=top ALIGN=left>String concatenation.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>!</TT> </TD>
<TD VALIGN=top ALIGN=left>Dereferencing (return the current
contents of a reference).</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>:=</TT></TD>
<TD VALIGN=top ALIGN=left>Reference assignment (update the
reference given as first argument with the value of the second
argument).</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>=</TT> </TD>
<TD VALIGN=top ALIGN=left>Structural equality test.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT><></TT> </TD>
<TD VALIGN=top ALIGN=left>Structural inequality test.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>==</TT> </TD>
<TD VALIGN=top ALIGN=left>Physical equality test.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>!=</TT> </TD>
<TD VALIGN=top ALIGN=left>Physical inequality test.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT><</TT> </TD>
<TD VALIGN=top ALIGN=left>Test “less than”.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT><=</TT> </TD>
<TD VALIGN=top ALIGN=left>Test “less than or equal”.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>></TT> </TD>
<TD VALIGN=top ALIGN=left>Test “greater than”.</TD>
</TR>
<TR><TD VALIGN=top ALIGN=left NOWRAP><TT>>=</TT> </TD>
<TD VALIGN=top ALIGN=left>Test “greater than or equal”.</TD>
</TR></TABLE></DIV><BR>
<BR>
<H3 CLASS="subsection"><A NAME="htoc71">6.7.5</A> Objects</H3> <A NAME="s:objects"></A>
<H4 CLASS="subsubsection">Object creation</H4>
<A NAME="@manual.kwd51"></A>
When <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> evaluates to a class body, <FONT COLOR=blue><TT>new</TT></FONT> <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>
evaluates to an object containing the instance variables and
methods of this class.<BR>
<BR>
When <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> evaluates to a class function, <FONT COLOR=blue><TT>new</TT></FONT> <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT>
evaluates to a function expecting the same number of arguments and
returning a new object of this class.<BR>
<BR>
<H4 CLASS="subsubsection">Immediate object creation</H4>
<A NAME="@manual.kwd52"></A>
Creating directly an object through the <FONT COLOR=blue><TT>object</TT> <FONT COLOR=maroon><TT><I>class-body</I></TT></FONT> <TT>end</TT></FONT>
construct is operationally equivalent to defining locally a <FONT COLOR=blue><TT>class</TT>
<FONT COLOR=maroon><TT><I>myclass</I></TT></FONT> <TT>=</TT> <TT>object</TT> <FONT COLOR=maroon><TT><I>class-body</I></TT></FONT> <TT>end</TT></FONT> —see sections
<A HREF="manual017.html#ss:class-body">6.9.2</A> and following for the syntax of <FONT COLOR=maroon><I><TT>class-body</TT></I></FONT>—
and immediately creating a single object from it by <FONT COLOR=blue><TT>new</TT></FONT> <FONT COLOR=maroon><I><TT>myclass</TT></I></FONT>.<BR>
<BR>
The typing of immediate objects is slightly different from explicitely
defining a class in two respects. First, the inferred object type may
contain free type variables. Second, since the class body of an
immediate object will never be extended, its self type can be unified
with a closed object type.<BR>
<BR>
<H4 CLASS="subsubsection">Message sending</H4>
The expression <FONT COLOR=maroon><TT><I>expr</I></TT> <FONT COLOR=blue><TT>#</TT></FONT> <TT><I>method-name</I></TT></FONT> invokes the method
<FONT COLOR=maroon><I><TT>method-name</TT></I></FONT> of the object denoted by <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>.<BR>
<BR>
If <FONT COLOR=maroon><I><TT>method-name</TT></I></FONT> is a polymorphic method, its type should be known at
the invocation site. This is true for instance if <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> is the name
of a fresh object (<FONT COLOR=blue><TT>let</TT></FONT> <FONT COLOR=maroon><I><TT>ident</TT></I></FONT> = <FONT COLOR=blue><TT>new</TT></FONT> <FONT COLOR=maroon><I><TT>class-path</TT></I></FONT> ... ) or if
there is a type constraint. Principality of the derivation can be
checked in the <TT>-principal</TT> mode.<BR>
<BR>
<H4 CLASS="subsubsection">Accessing and modifying instance variables</H4>
The instance variables of a class are visible only in the body of the
methods defined in the same class or a class that inherits from the
class defining the instance variables. The expression <FONT COLOR=maroon><I><TT>inst-var-name</TT></I></FONT>
evaluates to the value of the given instance variable. The expression
<FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT><-</TT></FONT> <TT><I>expr</I></TT></FONT> assigns the value of <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> to the instance
variable <FONT COLOR=maroon><I><TT>inst-var-name</TT></I></FONT>, which must be mutable. The whole expression
<FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT><-</TT></FONT> <TT><I>expr</I></TT></FONT> evaluates to <FONT COLOR=blue><TT>()</TT></FONT>.<BR>
<BR>
<H4 CLASS="subsubsection">Coercion</H4>
The type of an object can be coerced (weakened) to a supertype.
The expression <FONT COLOR=blue><TT>(</TT> <FONT COLOR=maroon><TT><I>expr</I></TT></FONT> <TT>:></TT> <FONT COLOR=maroon><TT><I>typexpr</I></TT></FONT> <TT>)</TT></FONT> coerces the expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
to type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT>.
The expression <FONT COLOR=blue><TT>(</TT></FONT> <FONT COLOR=maroon><TT><I>expr</I></TT> <FONT COLOR=blue><TT>:</TT></FONT> <TT><I>typexpr</I></TT></FONT><SUB>1</SUB> <FONT COLOR=blue><TT>:></TT></FONT> <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB> <FONT COLOR=blue><TT>)</TT></FONT> coerces the
expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT> from type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>1</SUB> to type <FONT COLOR=maroon><I><TT>typexpr</TT></I></FONT><SUB>2</SUB>.
The former operator will sometimes fail to coerce an expression <FONT COLOR=maroon><I><TT>expr</TT></I></FONT>
from a type <FONT COLOR=maroon><I><TT>t</TT></I></FONT><SUB>1</SUB> to a type <FONT COLOR=maroon><I><TT>t</TT></I></FONT><SUB>2</SUB> even if type <FONT COLOR=maroon><I><TT>t</TT></I></FONT><SUB>1</SUB> is a subtype of type
<FONT COLOR=maroon><I><TT>t</TT></I></FONT><SUB>2</SUB>: in the current implementation it only expands two levels of
type abbreviations containing objects and/or variants, keeping only
recursion when it is explicit in the class type. In case of failure,
the latter operator should be used.<BR>
<BR>
In a class definition, coercion to the type this class defines is the
identity, as this type abbreviation is not yet completely defined.<BR>
<BR>
<H4 CLASS="subsubsection">Object duplication</H4>
An object can be duplicated using the library function <TT>Oo.copy</TT>
(see
<A HREF="libref/Oo.hml">Module <TT>Oo</TT></A>). Inside a method, the expression
<FONT COLOR=blue><TT>{<</TT></FONT> <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>expr</I></TT></FONT> { <FONT COLOR=blue><TT>;</TT></FONT> <FONT COLOR=maroon><TT><I>inst-var-name</I></TT> <FONT COLOR=blue><TT>=</TT></FONT> <TT><I>expr</I></TT></FONT> } <FONT COLOR=blue><TT>>}</TT></FONT>
returns a copy of self with the given instance variables replaced by
the values of the associated expressions; other instance variables
have the same value in the returned object as in self.<BR>
<BR>
<BR>
<BR>
<HR>
<A HREF="manual014.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual008.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="manual016.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
|