/usr/share/doc/camlp5/html/revsynt.html is in camlp5 6.14-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- revsynt.html,v -->
<!-- Copyright (c) INRIA 2007-2014 -->
<title>revised syntax</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="styles/base.css"
title="Normal" />
<link rel="alternate" type="application/rss+xml" href="rss/camlp5.rss"
title="Camlp5"/>
</head>
<body>
<div id="menu">
<h1>- <a href="http://pauillac.inria.fr/~ddr/camlp5">Camlp5</a> -</h1>
<p class="subtitle">Version 6.14</p>
<ul>
<li><a href="index.html">Introduction</a></li>
<li><a href="strict.html">Transitional and Strict</a></li>
<li><a href="ptools.html">Parsing and printing tools</a></li>
</ul>
<ul>
<li>Parsing tools
<ul>
<li><a href="parsers.html">Stream parsers</a></li>
<li><a href="lexers.html">Stream lexers</a></li>
<li><a href="fparsers.html">Functional parsers</a></li>
<li><a href="bparsers.html">Backtracking parsers</a></li>
<li><a href="grammars.html">Extensible grammars</a></li>
</ul>
</li>
<li>Printing tools
<ul>
<li><a href="printers.html">Extensible printers</a></li>
<li><a href="pprintf.html">Pprintf</a></li>
<li><a href="pretty.html">Pretty print</a></li>
</ul>
</li>
<li>Language extensions
<ul>
<li><a href="locations.html">Locations</a></li>
<li><a href="ml_ast.html">Syntax tree</a></li>
<li><a href="ast_transi.html">Syntax tree - transi</a></li>
<li><a href="ast_strict.html">Syntax tree - strict</a></li>
<li><a href="q_ast.html">Quotation kit q_ast.cmo</a></li>
<li><a href="pcaml.html">The Pcaml module</a></li>
<li><a href="directives.html">Directives</a></li>
<li><a href="syntext.html">Extensions of syntax</a></li>
<li><a href="opretty.html">Extensions of printing</a></li>
<li><a href="redef.html">Redefining OCaml syntax</a></li>
<li><a href="quot.html">Quotations</a></li>
<li><a href="revsynt.html">Revised syntax</a></li>
<li><a href="scheme.html">Scheme syntax</a></li>
<li><a href="macros.html">Macros</a></li>
<li><a href="pragma.html">Pragma directive</a></li>
<li><a href="extfun.html">Extensible functions</a></li>
</ul>
</li>
<li>Appendix
<ul>
<li><a href="commands.html">Commands and Files</a></li>
<li><a href="library.html">Library</a></li>
<li><a href="sources.html">Camlp5 sources</a></li>
<li><a href="about.html">About Camlp5</a></li>
</ul>
</li>
</ul>
</div>
<div id="content">
<h1 class="top">The revised syntax</h1>
<p>The revised syntax is an alternative syntax of OCaml. It is close
to the normal syntax. We present here only the differences between
the two syntaxes.</p>
<p>Notice that there is a simple way to know how the normal syntax is
written in revised syntax: write the code in a file "foo.ml" in
normal syntax and type, in a shell:</p>
<pre>
camlp5o pr_r.cmo pr_rp.cmo foo.ml
</pre>
<p>And, conversely, how a file "bar.ml" written in revised syntax is
displayed in normal syntax:</p>
<pre>
camlp5r pr_o.cmo pr_op.cmo bar.ml
</pre>
<p>Even simpler, without creating a file:</p>
<pre>
camlp5o pr_r.cmo pr_op.cmo -impl -
... type in normal syntax ...
... type control-D ...
camlp5r pr_o.cmo pr_rp.cmo -impl -
... type in revised syntax ...
... type control-D ...
</pre>
<div id="tableofcontents">
<ol>
<li><a href="#a:Lexing">Lexing</a></li>
<li><a href="#a:Modules--Structure-and-Signature-items">Modules, Structure and Signature items</a></li>
<li><a href="#a:Expressions-and-Patterns">Expressions and Patterns</a>
<ul>
<li><a href="#b:Imperative-constructions">Imperative constructions</a></li>
<li><a href="#b:Tuples-and-Lists">Tuples and Lists</a></li>
<li><a href="#b:Records">Records</a></li>
<li><a href="#b:Irrefutable-patterns">Irrefutable patterns</a></li>
<li><a href="#b:Constructions-with-matching">Constructions with matching</a></li>
<li><a href="#b:Mutables-and-Assignment">Mutables and Assignment</a></li>
<li><a href="#b:Miscellaneous">Miscellaneous</a></li>
</ul>
</li>
<li><a href="#a:Types-and-Constructors">Types and Constructors</a></li>
<li><a href="#a:Streams-and-Parsers">Streams and Parsers</a></li>
<li><a href="#a:Classes-and-Objects">Classes and Objects</a></li>
<li><a href="#a:Labels-and-Variants">Labels and Variants</a></li>
</ol>
</div>
<h2 id="a:Lexing">Lexing</h2>
<ul>
<li>The character quote (<tt>'</tt>) can be written without backslash:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>'\''</tt></td>
<td><tt>'''</tt></td>
</tr>
</table>
</li>
</ul>
<h2 id="a:Modules--Structure-and-Signature-items">Modules, Structure and Signature items</h2>
<ul>
<li>Structure and signature items always end with a single semicolon
which is required.</li>
<li>In structures, the declaration of a value is introduced by the
keyword "value", instead of "let":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>let x = 42;;</tt></td>
<td><tt>value x = 42;</tt></td>
</tr>
<tr>
<td><tt>let x = 42 in x + 7;;</tt></td>
<td><tt>let x = 42 in x + 7;</tt></td>
</tr>
</table>
</li>
<li>In signatures, the declaration of a value is also introduced by
the keyword "value", instead of "val":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>val x : int;;</tt></td>
<td><tt>value x : int;</tt></td>
</tr>
</table>
</li>
<li>In signatures, abstract module types are represented by a quote
and an (any) identifier:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>module type MT;;</tt></td>
<td><tt>module type MT = 'a;</tt></td>
</tr>
</table>
</li>
<li>Functor application uses currying. Parentheses are not
required for the parameters:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = Set.Make(M).t;;</tt></td>
<td><tt>type t = (Set.Make M).t;</tt></td>
</tr>
<tr>
<td><tt>module M = Mod.Make (M1) (M2);;</tt></td>
<td><tt>module M = Mod.Make M1 M2;</tt></td>
</tr>
</table>
</li>
<li>It is possible to group several declarations together either in
an interface or in an implementation by enclosing them between
"declare" and "end" (this is useful when using syntax extensions
to generate several declarations from one). Example in an
interface:
<pre>
declare
type foo = [ Foo of int | Bar ];
value f : foo -> int;
end;
</pre>
</li>
</ul>
<h2 id="a:Expressions-and-Patterns">Expressions and Patterns</h2>
<h3 id="b:Imperative-constructions">Imperative constructions</h3>
<ul>
<li>The sequence is introduced by the keyword "do" followed by "{"
and terminated by "}"; it is possible to put a semicolon after the
last expression:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>e1; e2; e3; e4</tt></td>
<td><tt>do { e1; e2; e3; e4 }</tt></td>
</tr>
</table>
</li>
<li>The "do" after the "while" loop and the "for" loop are followed
by a "{" and the loop end with "}"; it is possible to put a
semicolon after the last expression:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>while e1 do</tt></td>
<td><tt>while e1 do {</tt></td>
</tr>
<tr>
<td><tt> e1; e2; e3</tt></td>
<td><tt> e1; e2; e3</tt></td>
</tr>
<tr>
<td><tt>done</tt></td>
<td><tt>}</tt></td>
</tr>
<tr>
<td><tt></tt></td>
<td><tt></tt></td>
</tr>
<tr>
<td><tt>for i = e1 to e2 do </tt></td>
<td><tt>for i = e1 to e2 do {</tt></td>
</tr>
<tr>
<td><tt> e1; e2; e3</tt></td>
<td><tt> e1; e2; e3</tt></td>
</tr>
<tr>
<td><tt>done</tt></td>
<td><tt>}</tt></td>
</tr>
</table>
</li>
</ul>
<h3 id="b:Tuples-and-Lists">Tuples and Lists</h3>
<ul>
<li>Parentheses are required in tuples:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>1, "hello", World</tt></td>
<td><tt>(1, "hello", World)</tt></td>
</tr>
</table>
</li>
<li>Lists are always enclosed with brackets. A list is a left
bracket, followed by a list of elements separated with semicolons,
optionally followed by colon-colon and an element, and ended by a
right bracket. Warning: the colon-colon is not an infix but is
just part of the syntactic construction.
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>x :: y</tt></td>
<td><tt>[x :: y]</tt></td>
</tr>
<tr>
<td><tt>[x; y; z]</tt></td>
<td><tt>[x; y; z]</tt></td>
</tr>
<tr>
<td><tt>x :: y :: z :: t</tt></td>
<td><tt>[x; y; z :: t]</tt></td>
</tr>
</table>
</li>
</ul>
<h3 id="b:Records">Records</h3>
<ul>
<li>In record update, parentheses are required around the initial
expression:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>{e with field = a}</tt></td>
<td><tt>{(e) with field = a}</tt></td>
</tr>
</table>
</li>
<li>It is allowable to use function binding syntax in record field
definitions:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>{field = fun a -> e}</tt></td>
<td><tt>{field a = e}</tt></td>
</tr>
</table>
</li>
</ul>
<h3 id="b:Irrefutable-patterns">Irrefutable patterns</h3>
<p>An <em>irrefutable pattern</em> is a pattern which is
syntactically visible and never fails. They are used in some
syntactic constructions. It is either:</p>
<ul>
<li>A variable,</li>
<li>The wildcard "_",</li>
<li>The constructor "()",</li>
<li>A tuple with irrefutable patterns,</li>
<li>A record with irrefutable patterns,</li>
<li>A type constraint with an irrefutable pattern.</li>
</ul>
<p>Notice that this definition is only syntactic: a constructor
belonging to a type having only one constructor is not considered as
an irrefutable pattern (except "()").</p>
<h3 id="b:Constructions-with-matching">Constructions with matching</h3>
<ul>
<li>The keyword "function" no longer exists. Only "fun" is used.</li>
<li>The pattern matching, in constructions with "fun", "match" and
"try" is closed with brackets: an open bracket "[" before the
first case, and a close bracket "]" after the last case:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>match e with</tt></td>
<td><tt>match e with</tt></td>
</tr>
<tr>
<td><tt> p1 -> e1</tt></td>
<td><tt>[ p1 -> e1</tt></td>
</tr>
<tr>
<td><tt>| p2 -> e2</tt></td>
<td><tt>| p2 -> e2 ]</tt></td>
</tr>
</table>
If there is only one case and if the pattern is irrefutable,
the brackets are not required. These examples work identically
in OCaml and in revised syntax:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>fun x -> x</tt></td>
<td><tt>fun x -> x</tt></td>
</tr>
<tr>
<td><tt>fun {foo=(y, _)} -> y</tt></td>
<td><tt>fun {foo=(y, _)} -> y</tt></td>
</tr>
</table>
</li>
<li>It is possible to write the empty function which always raises the
exception "Match_failure" when a parameter is applied. It is also possible to write and
empty "match", raising "Match_failure" after having evaluated its
expression and the empty "try", equivalent to its expression
without try:
<pre>
fun []
match e with []
try e with []
</pre>
</li>
<li>The patterns after "let" and "value" must be irrefutable. The
following OCaml expression:
<pre>
let f (x::y) = ...
</pre>
must be written:
<pre>
let f = fun [ [x::y] -> ...
</pre>
</li>
<li>It is possible to use a construction "where", equivalent to "let",
but usable only when where is only one binding. The expression:
<pre>
e1 where p = e
</pre>
is equivalent to:
<pre>
let p = e in e1
</pre>
</li>
</ul>
<h3 id="b:Mutables-and-Assignment">Mutables and Assignment</h3>
<ul>
<li>The statement "<tt><-</tt>" is written "<tt>:=</tt>":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>x.f <- y</tt></td>
<td><tt>x.f := y</tt></td>
</tr>
</table>
</li>
<li>The "ref" type is declared as a record type with one field named
"val", instead of "contents". The operator "!" does not exist any
more, and references are assigned like the other mutables:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>x := !x + y</tt></td>
<td><tt>x.val := x.val + y</tt></td>
</tr>
</table>
</li>
</ul>
<h3 id="b:Miscellaneous">Miscellaneous</h3>
<ul>
<li>The "<tt>else</tt>" is required in the "<tt>if</tt>"
statement:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>if a then b</tt></td>
<td><tt>if a then b else ()</tt></td>
</tr>
</table>
</li>
<li>The boolean operations "<tt>or</tt>" and "<tt>and</tt>" can only
be written with "<tt>||</tt>" and "<tt>&&</tt>":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>a or b & c</tt></td>
<td><tt>a || b && c</tt></td>
</tr>
<tr>
<td><tt>a || b && c</tt></td>
<td><tt>a || b && c</tt></td>
</tr>
</table>
</li>
<li>No more "<tt>begin end</tt>" construction. One must use
parentheses.</li>
<li>The operators as values are written with an backslash:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>(+)</tt></td>
<td><tt>\+</tt></td>
</tr>
<tr>
<td><tt>(mod)</tt></td>
<td><tt>\mod</tt></td>
</tr>
</table>
</li>
<li>Nested "as" patterns require parenthesis:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>function Some a as b, c -></tt></td>
<td><tt>fun [ ((Some a as b), c) -></tt></td>
</tr>
<tr>
<td><tt> ...</tt></td>
<td><tt> ...</tt></td>
</tr>
</table>
But they are not required before the right arrow:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>function Some a as b -></tt></td>
<td><tt>fun [ Some a as b -></tt></td>
</tr>
<tr>
<td><tt> ...</tt></td>
<td><tt> ...</tt></td>
</tr>
</table>
</li>
<li>The operators with special characters are not automatically
infix. To define infixes, use syntax extensions.
</li>
</ul>
<h2 id="a:Types-and-Constructors">Types and Constructors</h2>
<ul>
<li>The type constructors are before their type parameters, which
are curryfied:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>int list</tt></td>
<td><tt>list int</tt></td>
</tr>
<tr>
<td><tt>('a, bool) Hashtbl.t</tt></td>
<td><tt>Hashtbl.t 'a bool</tt></td>
</tr>
<tr>
<td><tt>type 'a foo = 'a list list</tt></td>
<td><tt>type foo 'a = list (list 'a)</tt></td>
</tr>
</table>
</li>
<li>The abstract types are represented by an unbound type variable:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type 'a foo;;</tt></td>
<td><tt>type foo 'a = 'b;</tt></td>
</tr>
<tr>
<td><tt>type bar;;</tt></td>
<td><tt>type bar = 'a;</tt></td>
</tr>
</table>
</li>
<li>Parentheses are required in tuples of types:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>int * bool</tt></td>
<td><tt>(int * bool)</tt></td>
</tr>
</table>
</li>
<li>In declarations of a concrete type, brackets must enclose the
constructor declarations:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = A of i | B;;</tt></td>
<td><tt>type t = [ A of i | B ];</tt></td>
</tr>
</table>
</li>
<li>It is possible to make the empty type, without constructor:
<pre>
type foo = [];
</pre>
</li>
<li>There is a syntax difference between data constructors with
several parameters and data constructors with one parameter of type
tuple:<br/><br/>
The declaration of a data constructor with several parameters
is done by separating the types with "and". In expressions and
patterns, these constructor parameters must be curryfied:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = C of t1 * t2;;</tt></td>
<td><tt>type t = [ C of t1 and t2 ];</tt></td>
</tr>
<tr>
<td><tt>C (x, y);;</tt></td>
<td><tt>C x y;</tt></td>
</tr>
</table>
The declaration of a data constructor with one parameter of type
tuple is done by using a tuple type. In expressions and patterns,
the parameter must not to be curryfied, since it is alone. In that
case the syntax of constructor parameters is the same between the
two syntaxes:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = D of (t1 * t2);;</tt></td>
<td><tt>type t = [ D of (t1 * t2) ];</tt></td>
</tr>
<tr>
<td><tt>D (x, y);;</tt></td>
<td><tt>D (x, y);</tt></td>
</tr>
</table>
</li>
<li>The bool constructors start with an uppercase letter. The identifiers
"true" and "false" are not keywords:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>true && false</tt></td>
<td><tt>True && False</tt></td>
</tr>
</table>
</li>
<li>In record types, the keyword "mutable" must appear after the
colon:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = {mutable x : t1};;</tt></td>
<td><tt>type t = {x : mutable t1};</tt></td>
</tr>
</table>
</li>
<li>Manifest types are with "==":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type 'a t = 'a option =</tt></td>
<td><tt>type t 'a = option 'a ==</tt></td>
</tr>
<tr>
<td><tt> None</tt></td>
<td><tt> [ None</tt></td>
</tr>
<tr>
<td><tt> | Some of 'a</tt></td>
<td><tt> | Some of 'a ]</tt></td>
</tr>
</table>
</li>
<li>Polymorphic types start with "<tt>!</tt>":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t =</tt></td>
<td><tt>type t =</tt></td>
</tr>
<tr>
<td><tt> { f : 'a . 'a list }</tt></td>
<td><tt> { f : ! 'a . list 'a }</tt></td>
</tr>
</table>
</li>
</ul>
<h2 id="a:Streams-and-Parsers">Streams and Parsers</h2>
<ul>
<li>The streams and the stream patterns are bracketed with "<tt>[:</tt>"
and "<tt>:]</tt>" instead of "<tt>[<</tt>" and "<tt>>]</tt>".
</li>
<li>The stream component "terminal" is written with a back-quote
instead of a quote:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>[< '1; '2; s; '3 >]</tt></td>
<td><tt>[: `1; `2; s; `3 :]</tt></td>
</tr>
</table>
</li>
<li>The cases of parsers are bracketed with "<tt>[</tt>" and
"<tt>]</tt>", as with "fun", "match" and "try". If there is one
case, the brackets are not required:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>parser</tt></td>
<td><tt>parser</tt></td>
</tr>
<tr>
<td><tt> [< 'Foo >] -> e</tt></td>
<td><tt>[ [: `Foo :] -> e</tt></td>
</tr>
<tr>
<td><tt>| [< p = f >] -> f;;</tt></td>
<td><tt>| [: p = f :] -> f ];</tt></td>
</tr>
<tr>
<td><tt>parser [< 'x >] -> x;;</tt></td>
<td><tt>parser [: `x :] -> x;</tt></td>
</tr>
</table>
</li>
<li>It is possible to write the empty parser raising the exception
"Stream.Failure" whatever parameter is applied, and the empty
stream matching always raising "Stream.Failure":
<pre>
parser []
match e with parser []
</pre>
</li>
<li>In normal syntax, the error indicator starts with a double question
mark, in revised syntax with a simple question mark:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>parser</tt></td>
<td><tt>parser</tt></td>
</tr>
<tr>
<td><tt> [< '1; '2 ?? "error" >] -></tt></td>
<td><tt> [: `1; `2 ? "error" :] -></tt></td>
</tr>
<tr>
<td><tt> ...</tt></td>
<td><tt> ...</tt></td>
</tr>
</table>
</li>
<li>In normal syntax, the component optimization starts with
"<tt>?!</tt>", in revised syntax with "<tt>!</tt>":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>parser</tt></td>
<td><tt>parser</tt></td>
</tr>
<tr>
<td><tt> [< '1; '2 ?! >] -></tt></td>
<td><tt> [: `1; `2 ! :] -></tt></td>
</tr>
<tr>
<td><tt> ...</tt></td>
<td><tt> ...</tt></td>
</tr>
</table>
</li>
</ul>
<h2 id="a:Classes-and-Objects">Classes and Objects</h2>
<ul>
<li>Object items end with a single semicolon which is required.</li>
<li>Class type parameters follow the class identifier:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>class ['a, 'b] point = ...</tt></td>
<td><tt>class point ['a, 'b] = ...</tt></td>
</tr>
<tr>
<td><tt>class c = [int] color;;</tt></td>
<td><tt>class c = color [int];</tt></td>
</tr>
</table>
</li>
<li>In the type of class with parameters, the type of the parameters
are between brackets. Example in signature:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>class c : int -> point;;</tt></td>
<td><tt>class c : [int] -> point;</tt></td>
</tr>
</table>
</li>
<li>The keywords "virtual" and "private" must be in this order:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>method virtual private m :</tt></td>
<td><tt>method virtual private m :</tt></td>
</tr>
<tr>
<td><tt> ...</tt></td>
<td><tt> ...</tt></td>
</tr>
<tr>
<td><tt>method private virtual m :</tt></td>
<td><tt>method virtual private m :</tt></td>
</tr>
<tr>
<td><tt> ...</tt></td>
<td><tt> ...</tt></td>
</tr>
</table>
</li>
<li>Object variables are introduced with "value" instead of "val":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>object val x = 3 end</tt></td>
<td><tt>object value x = 3; end</tt></td>
</tr>
</table>
</li>
<li>Type constraints in objects are introduced with "type" instead of
"constraint":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>object constraint 'a = int end</tt></td>
<td><tt>object type 'a = int; end</tt></td>
</tr>
</table>
</li>
</ul>
<h2 id="a:Labels-and-Variants">Labels and Variants</h2>
<ul>
<li>Labels in types must start with "<tt>~</tt>":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>val x : num:int -> bool;;</tt></td>
<td><tt>value x : ~num:int -> bool;</tt></td>
</tr>
</table>
</li>
<li>Types whose number of variants are fixed start with "<tt>[ =</tt>":
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = [`On | `Off];;</tt></td>
<td><tt>type t = [ = `On | `Off];</tt></td>
</tr>
</table>
</li>
<li>The "<tt>[</tt>" and the "<tt><</tt>" in variant types must
not be sticked:
<table width="75%" class="centered" cellspacing="0" cellpadding="0">
<tr>
<th align="left" class="half">OCaml</th>
<th align="left" class="half">Revised</th>
</tr>
<tr>
<td><tt>type t = [< `Foo | `Bar ];;</tt></td>
<td><tt>type t = [ < `Foo | `Bar ];</tt></td>
</tr>
</table>
</li>
</ul>
<a class="toplink" href="revsynt.html">↑</a>
<div class="trailer">
<hr style="margin:0" /><div style="font-size: 80%"><em>Copyright 2007-2014
Daniel de Rauglaudre (INRIA)</em></div>
<p class="bottom">
<a href="http://validator.w3.org/check?uri=referer"><img
alt="Valid XHTML 1.1" height="31" width="88" /></a>
</p>
</div>
</div>
</body>
</html>
|