forked from matsubara0507/simple-ismlnj
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmlnjkernel.py
904 lines (866 loc) · 96 KB
/
smlnjkernel.py
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
import html
import json
import re
from typing import Dict, List, Optional, Any
import re
import signal
from ipykernel.kernelbase import Kernel
from ipykernel.kernelapp import IPKernelApp
import pexpect
from subprocess import check_output
crlf_pat = re.compile(r"[\r\n]+")
REGEX_WORD = re.compile(r"(\w+)$")
SML_KEYWORDS = sorted(
[
"fun",
"true",
"false",
"orelse",
"andalso",
"if",
"then",
"else",
"val",
"let",
"in",
"end",
"fn",
"type",
"datatype",
"of",
"case",
"raise",
"exception",
"handle",
"use",
"real",
"int",
]
)
class REPLWrapper:
def __init__(self, cmd, orig_prompt: str, continuation_prompt: str):
self.child = pexpect.spawn(cmd, echo=False, encoding="utf-8")
self.prompt = re.compile(orig_prompt)
self.continuation_prompt = re.compile(continuation_prompt)
self._expect_prompt(timeout=1)
def _expect_prompt(self, timeout=-1):
return self.child.expect_list(
[self.prompt, self.continuation_prompt], timeout=timeout
)
def run_command(self, command: str, timeout: Optional[int] = -1) -> Optional[str]:
if not command:
raise ValueError("No command was given")
self.child.sendline(command)
# Command was fully submitted, now wait for the next prompt
if self._expect_prompt(timeout=timeout) == 1:
# We got the continuation prompt - command was incomplete
self.child.kill(signal.SIGINT)
self._expect_prompt(timeout=1)
raise ValueError(
"Continuation prompt found - input was incomplete:\n" + command
)
return self.child.before
def get_output(self) -> Optional[str]:
return self.child.before
PRIMARY_PROMPT = ">>>"
SECONDARY_PROMPT = "="
ERRORS_INFO: List[Dict[str, Any]] = [
{
"code": 1,
"msg": "argument of raise is not an exception",
"verbose": "The expression following the <code><b>raise</b></code> keyword should evaluate to an exception value, i.e. a value of type <code>exn</code>. In this case, the value has some other, inappropriate type. E.g.:",
"info": "<dd>\n The expression following the <code><b>raise</b></code> keyword should\n evaluate to an exception value, i.e. a value of type <code>exn</code>.\n In this case, the value has some other, inappropriate type. E.g.:\n <pre> raise 3;\n <i>stdIn:16.7 Error: argument of raise is not an exception [literal]\n raised: int\n in expression:\n raise 3</i>\n </pre>\n \n "
},
{
"code": 2,
"msg": "argument type variables in datatype replication",
"verbose": "In a datatype replication declaration, neither the type name on the left hand side nor the type path (longid) on the right hand side should be preceeded by formal type variable arguments, even if the right hand side datatype is of arity n>0.",
"info": "<dd>\n In a datatype replication declaration, neither the type name on the\n left hand side nor the type path (longid) on the right hand side\n should be preceeded by formal type variable arguments, even if the\n right hand side datatype is of arity n>0.\n <pre> datatype 'a T = A of 'a;\n <i>datatype 'a T = A of 'a</i>\n \n datatype 'a T1 = datatype T;\n <i>stdIn:18.1-18.28 Error: argument type variables in datatype replication</i>\n \n datatype T1 = datatype T;\n <i>datatype 'a T = A of 'a</i>\n </pre>\n \n "
},
{
"code": 3,
"msg": "can't find function arguments in clause",
"verbose": "This occurs when an formal parameter pattern is not supplied on the left hand side in a <code>fun</code> declaration, or one of the formal parameters of an infix function symbol is missing.",
"info": "<dd>\n This occurs when an formal parameter pattern is not supplied on the\n left hand side in a <code>fun</code> declaration, or one of the\n formal parameters of an infix function symbol is missing.\n <pre> fun f = 3;\n <i>stdIn:1.5 Error: can't find function arguments in clause</i>\n \n infix 3 ++;\n <i>infix 3 ++</i>\n \n fun (x xx) = 3;\n <i>stdIn:1.5-2.6 Error: can't find function arguments in clause\n stdIn:1.5-2.6 Error: illegal function symbol in clause</i>\n </pre>\n \n "
},
{
"code": 4,
"msg": "case object and rules don't agree",
"verbose": "The <em> case object </em> is the expression following the <code><b>case</b></code> keyword. It's type must agree with the type of the lhs patterns in the <em>rules</em> (<code><i>pat</i> => <i>exp</i></code>) following the <code><b>of</b></code> keyword. All the patterns of the rules also have to agree in type, but that is another error.",
"info": "<dd>\n The <em> case object </em> is the expression following the <code><b>case</b></code>\n keyword. It's type must agree with the type of the lhs patterns in\n the <em>rules</em> (<code><i>pat</i> => <i>exp</i></code>) following the\n <code><b>of</b></code> keyword. All the patterns of the rules also have\n to agree in type, but that is another error.\n <pre> case 3\n of true => 1\n | false => 2;\n <i>stdIn:1.1-25.16 Error: case object and rules don't agree [literal]\n rule domain: bool\n object: int\n in expression:\n (case 3\n of true => 1\n | false => 2)</i>\n </pre>\n \n "
},
{
"code": 5,
"msg": "clauses don't all have function name",
"verbose": "In a <code>fun</code> definition, the function name must appear in each clause. If it is omitted from one or more clauses, this error results.",
"info": "<dd>\n In a <code>fun</code> definition, the function name must appear in\n each clause. If it is omitted from one or more clauses, this error results.\n <pre> fun f nil = 1\n | (x::y) = x;\n <i>stdIn:1.5-17.15 Error: clauses don't all have function name</i>\n </pre>\n This error is also reported when the function name in two\n clauses of the function definition differ, for instance because\n of a misspelling.\n <pre> fun test (SOME s) = true\n | teat (NONE) = false;\n stdIn:120.5-121.24 Error: clauses don't all have function name\n </pre>\n \n "
},
{
"code": 6,
"msg": "clauses don't all have same number of patterns",
"verbose": "In a <code>fun</code> declaration, each clause, or rule, separated by <code>|</code> (vertical bar symbol), has to have the same number of curried arguments.",
"info": "<dd>\n In a <code>fun</code> declaration, each clause, or rule, separated by\n <code>|</code> (vertical bar symbol), has to have the same number of\n curried arguments.\n <pre> fun f x y = 3\n | f a b c = 4;\n <i>stdIn:1.5-26.16 Error: clauses don't all have same number of patterns\n stdIn:24.6-26.16 Error: types of rules don't agree [tycon mismatch]\n earlier rule(s): 'Z * 'Y -> int\n this rule: 'X * 'W * 'V -> int\n in rule:\n (a,b,c) => 4</i>\n </pre>\n \n "
},
{
"code": 7,
"msg": "constant constructor applied to argument in pattern: %",
"verbose": "A constant constructor like <code>nil</code> can't be applied to an argument in a pattern.",
"info": "<dd>\n A constant constructor like <code>nil</code> can't be applied to an\n argument in a pattern.\n <pre> val nil x = [];\n <i>stdIn:1.5-24.8 Error: constant constructor applied to argument in pattern:nil</i>\n </pre>\n \n "
},
{
"code": 8,
"msg": "constructor and argument don't agree in pattern",
"verbose": "A nonconstant constructor in a pattern must be applied to an argument pattern of the appropriate type (i.e. the domain type of the constructor).",
"info": "<dd>\n A nonconstant constructor in a pattern must be applied to an argument\n pattern of the appropriate type (i.e. the domain type of the constructor).\n <pre> datatype t = A of int;\n val A true = A 3;\n <i>stdIn:1.1-26.3 Error: constructor and argument don't agree in pattern [tycon mismatch]\n constructor: int -> t\n argument: bool\n in pattern:\n A true</i>\n </pre>\n \n "
},
{
"code": 9,
"msg": "data constructor % used without argument in pattern",
"verbose": "A nonconstant constructor must be applied to an argument when it is used in a pattern (though not necessarily when it is used in an expression).",
"info": "<dd>\n A nonconstant constructor must be applied to an argument when it is\n used in a pattern (though not necessarily when it is used in an expression).\n <pre> datatype t = A of int\n val A = A 3;\n <i>stdIn:17.5-17.12 Error: data constructor A used without argument in pattern</i>\n </pre>\n \n "
},
{
"code": 10,
"msg": "datatype % does not match specification",
"verbose": "Usually occurs because the constructors for a datatype declared in a structure don't agree with the constructors (in names or number) of a signature that the structure must match.",
"info": "<dd>\n Usually occurs because the constructors for a datatype declared in a\n structure don't agree with the constructors (in names or number) of\n a signature that the structure must match.\n <pre> signature S =\n sig\n datatype t = A of int\n end;\n <i>signature S = sig datatype t = A of int end</i>\n \n structure A : S =\n struct\n datatype t = A of int | B\n end;\n <i>stdIn:1.1-27.4 Error: datatype t does not match specification\n constructors in actual only: B</i>\n </pre>\n \n "
},
{
"code": 11,
"msg": "datatype % has duplicate constructor name(s): %, %",
"verbose": "The names of the constructors of a given datatype must all be distinct.",
"info": "<dd>\n The names of the constructors of a given datatype must all be distinct.\n <pre> datatype t = A | B | A of int;\n <i>stdIn:1.1-26.5 Error: datatype t has duplicate constructor name(s): A</i>\n </pre>\n \n "
},
{
"code": 12,
"msg": "dependency cycle in instantiate",
"verbose": "The <em>instantiate</em> process takes a signature and creates a dummy structure matching that signature with no extraneous sharing (i.e. no types are identified that don't need to be). This process can fail because of various kinds of circularities. An example of one of the simpler forms of circularity would be:",
"info": "<dd>\n The <em>instantiate</em> process takes a signature and creates a dummy\n structure matching that signature with no extraneous sharing (i.e.\n no types are identified that don't need to be). This process can\n fail because of various kinds of circularities. An example of one\n of the simpler forms of circularity would be:\n <pre> signature S =\n sig\n type u\n datatype s = A of u\n sharing type u = s\n end;\n <i>stdIn:16.1-21.4 Error: dependency cycle in instantiate</i>\n </pre>\n By default, every signature is instantiated when it is declared, to\n detect errors as early as possible. However, signature instantiation\n is strictly only necessary when a signature is used as a functor\n parameter signature or in an opaque (<code>:></code>) signature constraint.\n <p>\n \n "
},
{
"code": 13,
"msg": "duplicate constructor specifications for % caused by include",
"verbose": "A signature should have only one specification of a given value or constructor name. A common way that multiple constructor specifications for a name can occur is if a constructor is specified explicitly, and also implicitly through an included signature.",
"info": "<dd>\n A signature should have only one specification of a given value or\n constructor name. A common way that multiple constructor\n specifications for a name can occur is if a constructor is\n specified explicitly, and also implicitly through an included\n signature.\n <pre> signature S =\n sig\n datatype t = A of int\n end;\n <i>signature S = sig datatype t = A of int end</i>\n \n signature T =\n sig\n datatype u = A\n include S\n end;\n <i>stdIn:27.3-28.13 Error: duplicate constructor specifications for A caused by include</i>\n </pre>\n \n "
},
{
"code": 14,
"msg": "duplicate exception declaration",
"verbose": "An exception name is declared multiple times in a single exception declaration.",
"info": "<dd>\n An exception name is declared multiple times in a single exception\n declaration.\n <pre> exception E of int\n and E of bool;\n <i>stdIn:17.1-18.14 Error: duplicate exception declaration: E</i>\n </pre>\n Note that it is ok if the same exception name is declared in different\n exception declarations, as in the following.\n <pre> exception E of int;\n <i>exception E of int</i>\n \n exception E of bool;\n <i>exception E of bool</i>\n </pre>\n \n "
},
{
"code": 15,
"msg": "duplicate function name in val rec dec",
"verbose": "When declaring several functions in a single <code>val rec</code> declaration, the names of the functions must be distinct.",
"info": "<dd>\n When declaring several functions in a single <code>val rec</code>\n declaration, the names of the functions must be distinct.\n <pre> val rec f = (fn x => x)\n and f = (fn y => y + 3);\n <i>stdIn:21.1-22.24 Error: duplicate function name in val rec dec: f</i>\n </pre>\n \n "
},
{
"code": 16,
"msg": "duplicate function names in fun dec",
"verbose": "When declaring several functions in a single <code>fun</code> declaration, the names of the functions must be distinct.",
"info": "<dd>\n When declaring several functions in a single <code>fun</code>\n declaration, the names of the functions must be distinct.\n <pre> fun f x = x\n and f y = y + 3;\n <i>stdIn:1.1-23.16 Error: duplicate function names in fun dec: f</i>\n </pre>\n \n "
},
{
"code": 17,
"msg": "duplicate label in record",
"verbose": "The label names in a record expression or pattern must be distinct.",
"info": "<dd>\n The label names in a record expression or pattern must be distinct.\n <pre> {a=3,b=true,a=\"abc\"};\n <i>stdIn:1.1-1.21 Error: duplicate label in record: a</i>\n fun f {a=x,a=y} = 3;\n <i>stdIn:2.2-2.11 Error: duplicate label in record: a</i>\n </pre>\n \n "
},
{
"code": 18,
"msg": "duplicate specifications for % % in signature",
"verbose": "Only one specification for a given name in a given name space is allowed in signatures. Values and constructors (including exception constructors) are in one name space; types, structures, and functors are disjoint name spaces. So <code>x</code> cannot be specified twice as a value or constructor, but it can be specified as a value, as a type, as a structure, and as a functor in the same signature.",
"info": "<dd>\n Only one specification for a given name in a given name space is\n allowed in signatures. Values and constructors (including exception\n constructors) are in one name space; types, structures, and functors\n are disjoint name spaces. So <code>x</code> cannot be specified\n twice as a value or constructor, but it can be specified as a\n value, as a type, as a structure, and as a functor in the same\n signature.\n <pre> signature S =\n sig\n val x : int\n val x : bool\n end;\n <i>stdIn:20.3-21.16 Error: duplicate specifications for variable or constructor x in signature</i>\n \n signature S =\n sig\n type t\n type t\n end;\n <i>stdIn:24.3-25.10 Error: duplicate specifications for type constructor t in signature</i>\n signature S =\n sig\n exception Foo\n exception Foo of int\n end;\n <i>stdIn:28.3-29.24 Error: duplicate specifications for variable or constructor Foo in signature</i>\n \n signature S =\n sig\n structure A : sig end\n structure A : sig end\n end;\n <i>stdIn:32.3-33.25 Error: duplicate specifications for structure A in signature</i>\n \n signature S =\n sig\n val x : int\n datatype t = x\n end;\n <i>stdIn:36.3-37.18 Error: duplicate specifications for variable or constructor x in signature</i>\n \n signature S =\n sig\n val x : int\n type x\n structure x : sig end\n end;\n <i>signature S =\n sig\n val x : int\n type x\n structure x : sig end\n end</i>\n </pre>\n \n "
},
{
"code": 19,
"msg": "duplicate specifications for functor % caused by include",
"verbose": "Multiple specifications for a functor name occur in a signature, with one of the later ones introduced via an <code>include</code> spec. If the included functor spec comes first, you get error [19] instead.",
"info": "<dd>\n Multiple specifications for a functor name occur in a signature, with one of\n the later ones introduced via an <code>include</code> spec. If the\n included functor spec comes first, you get error [19] instead.\n <pre> signature S1 =\n sig\n functor F () : sig end\n end;\n <i>signature S1 = sig functor F : (<param>: <sig>) : <sig> end</sig></sig></i>\n \n signature S2 =\n sig\n include S1\n functor F(X: sig val x : int end): sig end\n end;\n <i>stdIn:55.3-56.46 Error: duplicate specifications for functor F in signature</i>\n \n signature S2 =\n sig\n functor F(X: sig val x : int end): sig end\n include S1\n end;\n <i>stdIn:59.3-60.14 Error: duplicate specifications for functor F caused by include</i>\n </pre>\n \n "
},
{
"code": 20,
"msg": "duplicate specifications for structure % caused by include",
"verbose": "Multiple specifications for a structure name occur in a signature, with one of the later ones introduced via an <code>include</code> spec. If the included structure spec comes first, you get error [19] instead.",
"info": "<dd>\n Multiple specifications for a structure name occur in a signature, with one of\n the later ones introduced via an <code>include</code> spec. If the\n included structure spec comes first, you get error [19] instead.\n <pre> signature S1 =\n sig\n structure A : sig end\n end;\n <i>signature S1 = sig structure A : sig end end</i>\n \n signature S2 =\n sig\n structure A : sig val x : int end\n include S1\n end;\n <i>stdIn:67.3-68.14 Error: duplicate specifications for structure A caused by include</i>\n \n signature S3 =\n sig\n include S1\n structure A : sig val x : int end\n end;\n <i>stdIn:71.3-72.37 Error: duplicate specifications for structure A in signature</i>\n </pre>\n \n "
},
{
"code": 21,
"msg": "duplicate specifications for type % caused by include",
"verbose": "Multiple specifications for a type name occur in a signature, with one of the later ones introduced via an <code>include</code> spec. If the included structure spec comes first, you get error [19] instead.",
"info": "<dd>\n Multiple specifications for a type name occur in a signature, with one of\n the later ones introduced via an <code>include</code> spec. If the\n included structure spec comes first, you get error [19] instead.\n <pre> signature S1 =\n sig\n type t\n end;\n <i>signature S1 = sig type t end</i>\n \n signature S2 =\n sig\n type 'a t\n include S1\n end;\n <i>stdIn:79.3-80.14 Error: duplicate specifications for type t caused by include</i>\n \n signature S3 =\n sig\n include S1\n type 'a t\n end;\n <i>stdIn:83.3-84.13 Error: duplicate specifications for type constructor t in signature</i>\n </pre>\n \n "
},
{
"code": 22,
"msg": "duplicate type definition",
"verbose": "A type name is defined twice in a single simultaneous type declaration (i.e. type declarations separated by <code><strong>and</strong></code>. If the simultaneous declaration is split into separate declarations, there is no error.",
"info": "<dd>\n A type name is defined twice in a single simultaneous type\n declaration (i.e. type declarations separated by\n <code><strong>and</strong></code>.\n If the simultaneous declaration is split into\n separate declarations, there is no error.\n <pre> type t = int\n and t = bool;\n <i>stdIn:17.1-18.13 Error: duplicate type definition: t</i>\n \n type t = int;\n <i>type t = int</i>\n type t = bool;\n <i>type t = bool</i>\n </pre>\n \n "
},
{
"code": 23,
"msg": "duplicate type names in type declaration",
"verbose": "A type name is defined multiple times in a datatype declaration (including possibly in the <code><strong>withtype</strong></code> part.",
"info": "<dd>\n A type name is defined multiple times in a datatype declaration\n (including possibly in the <code><strong>withtype</strong></code> part.\n <pre> datatype t = A\n and t = B;\n <i>stdIn:1.1-19.10 Error: duplicate type names in type declaration: t</i>\n \n datatype t = A\n withtype t = int;\n <i>stdIn:1.1-20.17 Error: duplicate type names in type declaration: t</i>\n </pre>\n \n "
},
{
"code": 24,
"msg": "duplicate type variable name",
"verbose": "A type variable name is repeated in a type parameter list, when defining an n-ary type or datatype constructor, or explicitly binding types in a value declaration.",
"info": "<dd>\n A type variable name is repeated in a type parameter list, when\n defining an n-ary type or datatype constructor, or explicitly binding\n types in a value declaration.\n <pre> type ('a,'a) t = 'a * 'a;\n <i>stdIn:21.4-21.11 Error: duplicate type variable name: a</i>\n \n datatype ('a,'a) t = A of 'a;\n <i>stdIn:1.1-21.15 Error: duplicate type variable name: a</i>\n \n fun ('a,'a) f(x:'a) = x;\n <i>stdIn:1.1-21.10 Error: duplicate type variable name: a</i>\n </pre>\n \n "
},
{
"code": 25,
"msg": "duplicate value specifications for % caused by include",
"verbose": "Multiple specifications for a value name occur in a signature, with one of the later ones introduced via an <code>include</code> spec. If the included structure spec comes first, you get error [19] instead. It does not matter whether the multiple value specifications give the same type or not.",
"info": "<dd>\n Multiple specifications for a value name occur in a signature, with one of\n the later ones introduced via an <code>include</code> spec. If the\n included structure spec comes first, you get error [19] instead. It\n does not matter whether the multiple value specifications give the\n same type or not.\n <pre> signature S1 =\n sig\n val x : int\n end;\n <i>signature S1 = sig val x : int end</i>\n \n signature S2 =\n sig\n val x : bool\n include S1\n end;\n <i>stdIn:29.3-30.14 Error: duplicate value specifications for x caused by include</i>\n \n signature S3 =\n sig\n val x : int\n include S1\n end;\n <i>stdIn:33.3-34.14 Error: duplicate value specifications for x caused by include</i>\n \n signature S4 =\n sig\n include S1\n val x : int\n end;\n <i>stdIn:37.3-38.15 Error: duplicate specifications for variable or constructor x in signature</i>\n </pre>\n \n "
},
{
"code": 26,
"msg": "duplicate variable in pattern(s)",
"verbose": "A variable may only occur once in a pattern (or in the sequence of argument patterns of a curried function declaration.",
"info": "<dd>\n A variable may only occur once in a pattern (or in the sequence of argument\n patterns of a curried function declaration.\n <pre> fun f(x,x) = x;\n <i>stdIn:1.5-2.10 Error: duplicate variable in pattern(s): x</i>\n \n fun f x x = x;\n <i>stdIn:1.5-2.9 Error: duplicate variable in pattern(s): x</i>\n \n val (x,x) = (3,3);\n <i>stdIn:1.1-36.3 Error: duplicate variable in pattern(s): x</i>\n </pre>\n \n "
},
{
"code": 27,
"msg": "explicit type variable cannot be generalized at its binding declaration: %",
"verbose": "A type variable used in a type constraint within a value expression or declaration must be generalized at the appropriate point (determined either explicitly or implicitly). If the type variable cannot be generalized at that point because of the value restriction, this error message results.",
"info": "<dd>\n A type variable used in a type constraint within a value expression or\n declaration must be generalized at the appropriate point (determined\n either explicitly or implicitly). If the type variable cannot be generalized\n at that point because of the value restriction, this error message results.\n <pre> val x : 'a list = (fn x => x) nil;\n <i>stdIn:1.1-37.14 Error: explicit type variable cannot be generalized at its binding declaration: 'a</i>\n \n val 'a (x: 'a list) = (fn x => x) nil;\n <i>stdIn:1.1-38.5 Error: explicit type variable cannot be generalized at its binding declaration: 'a</i>\n </pre>\n \n "
},
{
"code": 28,
"msg": "expression and handler don't agree",
"verbose": "The type of the right hand side of the each rule in an exception handler must agree with the type of the base expression that the handler is attached to, because the value returned by the entire handle expression is either that of the base expression or the value returned by one of the handler rules.",
"info": "<dd>\n The type of the right hand side of the each rule in an exception\n handler must agree with the type of the base expression that the\n handler is attached to, because the value returned by the entire\n handle expression is either that of the base expression or the\n value returned by one of the handler rules.\n <pre> fun f x = (hd x)+1 handle Empty => true;\n <i>stdIn:2.6-38.7 Error: expression and handler don't agree [literal]\n body: int\n handler range: bool\n in expression:\n hd x + 1\n handle\n Empty => true\n | exn => raise exn</i>\n </pre>\n \n "
},
{
"code": 29,
"msg": "expression or pattern begins with infix identifier \"%\"",
"verbose": "An infix identifier cannot be the first identifier in an expression, unless it is preceded by the <code><strong>op</strong></code> keyword.",
"info": "<dd>\n An infix identifier cannot be the first identifier in an expression,\n unless it is preceded by the <code><strong>op</strong></code> keyword.\n <pre> +(2,3);\n <i>stdIn:1.1 Error: expression or pattern begins with infix identifier \"+\"</i>\n \n op +(2,3);\n <i>val it = 5 : int</i>\n </pre>\n \n "
},
{
"code": 30,
"msg": "expression or pattern ends with infix identifier \"%\"",
"verbose": "An expression cannot end with an infix identifier. Perhaps there is a missing <code><strong>op</strong></code> keyword.",
"info": "<dd>\n An expression cannot end with an infix identifier. Perhaps there is\n a missing <code><strong>op</strong></code> keyword.\n <pre> 2 +;\n <i>stdIn:40.4 Error: expression or pattern ends with infix identifier \"+\"\n stdIn:40.1-40.4 Error: operator is not a function [literal]\n operator: int\n in expression:\n 2 +</i>\n \n (fn x => x) +;\n <i>stdIn:40.3 Error: expression or pattern ends with infix identifier \"+\"</i>\n \n (fn x => x) op +;\n <i>val it = fn : int * int -> int</i>\n </pre>\n \n "
},
{
"code": 31,
"msg": "fixity precedence must be between 0 and 9",
"verbose": "This one is obvious. When defining new infix operators, you have to fit them into the existing precedence ranking, which is limited to ten levels, from 0 to 9, with higher numbers giving stronger precedence. See the <a href=\"basis/pages/top-level-chapter.html\">Top Level Environment</a> chapter of the Basis documentation for the precedences of the predefined infix operators.",
"info": "<dd>\n This one is obvious. When defining new infix operators, you have\n to fit them into the existing precedence ranking, which is limited to\n ten levels, from 0 to 9, with higher numbers giving stronger precedence.\n See the <a href=\"basis/pages/top-level-chapter.html\">Top Level Environment</a>\n chapter of the Basis documentation for the precedences of the predefined\n infix operators.\n <pre> infix 10 ++;\n <i>stdIn:43.7-43.9 Error: fixity precedence must be between 0 and 9</i>\n \n infix ~2 ++;\n <i>stdIn:2.2-2.4 Error: fixity precedence must be between 0 and 9</i>\n </pre>\n \n "
},
{
"code": 32,
"msg": "found data constructor instead of exception",
"verbose": "In a context where an exception constructor identifier was expected, a dataconstructor identifier was found instead.",
"info": "<dd>\n In a context where an exception constructor identifier was expected,\n a dataconstructor identifier was found instead.\n <pre> exception Foo = nil;\n <i>stdIn:17.1-17.20 Error: found data constructor instead of exception</i>\n </pre>\n \n "
},
{
"code": 33,
"msg": "found variable instead of exception",
"verbose": "In a context where an exception constructor identifier was expected, a value variable was found instead.",
"info": "<dd>\n In a context where an exception constructor identifier was expected,\n a value variable was found instead.\n <pre> val x = 3;\n <i>val x = 3 : int</i>\n exception Foo = x;\n <i>stdIn:18.1-18.18 Error: found variable instead of exception</i>\n </pre>\n \n "
},
{
"code": 34,
"msg": "handler domain is not exn",
"verbose": "In the rules following the <code><strong>handler</strong></code> keyword, the type of the patterns on the left hand side the rule must be <code>exn</code>. In the example below, the first error message is caused by a mismatch with an implicit default rule that handles exceptions not handled by the explicit rules of the handler.",
"info": "<dd>\n In the rules following the <code><strong>handler</strong></code>\n keyword, the type of the patterns on the left hand side the rule\n must be <code>exn</code>. In the example below, the first error\n message is caused by a mismatch with an implicit default rule that\n handles exceptions not handled by the explicit rules of the handler.\n <pre> 3 handle nil => 4;\n <i>stdIn:1.1-18.7 Error: types of rules don't agree [tycon mismatch]\n earlier rule(s): 'Z list -> int\n this rule: exn -> 'Y\n in rule:\n exn => raise exn\n stdIn:1.1-18.7 Error: handler domain is not exn [tycon mismatch]\n handler domain: 'Z list\n in expression:\n 3\n handle\n nil => 4\n | exn => raise exn</i>\n </pre>\n \n "
},
{
"code": 35,
"msg": "ill-formed datatype spec",
"verbose": "In a datatype replication specification in a signature, type parameters were found on the left hand side of the specification.",
"info": "<dd>\n In a datatype replication specification in a signature, type\n parameters were found on the left hand side of the specification.\n <pre> signature S =\n sig\n datatype 'a t = datatype bool\n end;\n <i>stdIn:26.3-26.33 Error: ill-formed datatype spec</i>\n </pre>\n \n "
},
{
"code": 36,
"msg": "illegal (multiple?) type constraints in AS pattern",
"verbose": "The value variable in front of the <code><strong>as</strong></code> keyword can have a type constraint, but only one. This error also occurs in other circumstances, as illustrated by the second example.",
"info": "<dd>\n The value variable in front of the <code><strong>as</strong></code>\n keyword can have a type constraint, but only one. This error also\n occurs in other circumstances, as illustrated by the second example.\n <pre> val x : int list : int list as y::z = [1,2];\n <i>stdIn:29.5-29.36 Error: illegal (multiple?) type constraints in AS pattern</i>\n \n val (x: int list) as (y::z : int list) = [1];\n <i>stdIn:1.5-24.10 Error: illegal (multiple?) type constraints in AS pattern\n stdIn:1.5-24.10 Error: parentheses illegal around variable in AS pattern</i>\n \n val x : int list as (y::z) = [1,2];\n <i>stdIn:1.1-24.6 Warning: binding not exhaustive\n x as y :: z = ...\n val x = [1,2] : int list\n val y = 1 : int\n val z = [2] : int list</i>\n </pre>\n \n "
},
{
"code": 37,
"msg": "illegal function symbol in clause",
"verbose": "In a function declaration, the left hand side between the keyword <code><strong>fun</strong></code> and the equal sign must be a well-formed applicative term, and the operator (i.e. the function part of the top-level application) of this term must be a simple identifier. If the application has an infix operator, it must be parenthesized (unless followed immediately by a type constraint or the equal sign); otherwise it may not be parenthesized.",
"info": "<dd>\n In a function declaration, the left hand side between\n the keyword <code><strong>fun</strong></code> and the equal sign\n must be a well-formed applicative term, and the operator (i.e. the function\n part of the top-level application) of this term must be a simple\n identifier. If the application has an infix operator, it must\n be parenthesized (unless followed immediately by a type constraint\n or the equal sign); otherwise it may not be parenthesized.\n <pre> fun (f x) = 3; (* bad parentheses *)\n <i>stdIn:1.5-2.5 Error: can't find function arguments in clause\n stdIn:1.5-2.5 Error: illegal function symbol in clause</i>\n \n fun (x+y) = 3; (* ok; redefines infix + operator *)\n <i>val + = fn : 'a * 'b -> int</i>\n </pre>\n \n "
},
{
"code": 38,
"msg": "inconsistent arities in type sharing % = %: % has arity % and % has arity %",
"verbose": "Two types involved in a type sharing constraint have different arities.",
"info": "<dd>\n Two types involved in a type sharing constraint have different\n arities.\n <pre> signature XSIG = sig\n datatype ('a, 'b) t = A of 'a | B of 'b\n end\n \n functor F\n (type u\n structure X: XSIG\n sharing type X.t = u) =\n struct\n end\n \n <i>stdIn:49.11-54.6 Error: inconsistent arities in type sharing t = u : t\n has arity 2 and u has arity 0.</i>\n </pre>\n \n "
},
{
"code": 39,
"msg": "inconsistent equality properties in type sharing",
"verbose": "This error occurs when type constructors with incompatible equality properties are equated by sharing constraints. When this happens, the signature is not consistent, and could not be successfully matched.",
"info": "<dd>\n This error occurs when type constructors with incompatible equality\n properties are equated by sharing constraints. When this happens, the\n signature is not consistent, and could not be successfully matched.\n <pre> signature S =\n sig\n eqtype t\n datatype u = U of int -> int (* not an equality type *)\n sharing type t = u\n end;\n <i>stdIn:17.1-22.4 Error: inconsistent equality properties in type sharing</i>\n </pre>\n \n "
},
{
"code": 40,
"msg": "infix operator \"%\" used without \"op\" in fun dec",
"verbose": "A function symbol declared to be an infix symbol is used in a function declaration used to declare nonfix functions.",
"info": "<dd>\n A function symbol declared to be an infix symbol is used in a\n function declaration used to declare nonfix functions.\n <pre> infix foo;\n <i>infix foo</i>\n fun foo (x,y) = x + y;\n <i>stdIn:34.5-34.8 Error: infix operator \"foo\" used without \"op\" in fun dec</i>\n </pre>\n The correct definition is:\n <pre> fun op foo(x,y) = x +y;\n <i>val foo = fn : int * int -> int</i>\n </pre>\n \n "
},
{
"code": 41,
"msg": "infix operator required, or delete parentheses",
"verbose": "The first term following keyword <code><strong>fun</strong></code> in a function declaration is a parenthesized application, implying an infix application, but the middle subterm is not an infix symbol.",
"info": "<dd>\n The first term following keyword <code><strong>fun</strong></code> in\n a function declaration is a parenthesized application, implying an\n infix application, but the middle subterm is not an infix symbol.\n <pre> fun (x f y) = (); (* would work if \"f\" were infix *)\n <i>stdIn:18.8 Error: infix operator required, or delete parentheses</i>\n \n fun x f y = (); (* ok, but maybe not what was intended *)\n <i>val x = fn : 'a -> 'b -> unit</i>\n </pre>\n \n "
},
{
"code": 42,
"msg": "infix symbol \"%\" used where a nonfix identifier was expected",
"verbose": "In a <code><strong>val rec</strong></code> declaration, the if the identifier being declared (on the left hand side of the declaration) is an infix symbol, it must be preceeded by the <code><strong>op</strong></code> keyword.",
"info": "<dd>\n In a <code><strong>val rec</strong></code> declaration, the if the\n identifier being declared (on the left hand side of the declaration) is\n an infix symbol, it must be preceeded by the <code><strong>op</strong></code>\n keyword.\n <pre> infix ++;\n <i>infix ++</i>\n val rec ++ = (fn x => x);\n <i>stdIn:17.9-17.11 Error: infix symbol \"++\" used where a nonfix identifier was expected</i>\n \n val rec op ++ = (fn x => x);\n <i>val ++ = fn : 'a -> 'a</i>\n </pre>\n \n "
},
{
"code": 43,
"msg": "install_pp: empty path",
"verbose": "The function <code>Compiler.PPTable.install_pp</code> installs a user-defined pretty printer function (the second argument) for a generative (i.e. datatype or abstype) designated by the first argument, which must be a nonempty list of strings that can be interpreted as a symbolic path (longTyCon) naming a datatype or abstract type in the current environment. This function should only be called at top level.",
"info": "<dd>\n The function <code>Compiler.PPTable.install_pp</code> installs a\n user-defined pretty printer function (the second argument) for a\n generative (i.e. datatype or abstype) designated by the first\n argument, which must be a nonempty list of strings that can be\n interpreted as a symbolic path (longTyCon) naming a\n datatype or abstract type in the current environment.\n This function should only be called at top level.\n <pre> Compiler.PPTable.install_pp [] (fn x => fn y => ());\n <i>Error: install_pp: empty path</i>\n </pre>\n \n "
},
{
"code": 44,
"msg": "install_pp: nongenerative type constructor",
"verbose": "The function <code>Compiler.PPTable.install_pp</code> installs a user-defined pretty printer function (the second argument) for a generative (i.e. datatype or abstype) designated by the first argument, which must be a nonempty list of strings that can be interpreted as a symbolic path (longTyCon) naming a datatype or abstype in the current environment. This function should only be called at top level.",
"info": "<dd>\n The function <code>Compiler.PPTable.install_pp</code> installs a\n user-defined pretty printer function (the second argument) for a\n generative (i.e. datatype or abstype) designated by the first\n argument, which must be a nonempty list of strings that can be\n interpreted as a symbolic path (longTyCon) naming a datatype\n or abstype in the current environment. This function should only\n be called at top level.\n <pre> Compiler.PPTable.install_pp [\"t\"] (fn x => fn y => ());\n <i>Error: install_pp: nongenerative type constructor</i>\n </pre>\n \n "
},
{
"code": 45,
"msg": "int constant too large",
"verbose": "Integer literal in program is too large. Default integers are represented using 31 bits, and range from ~1073741824 to 1073741823, or from:",
"info": "<dd>\n Integer literal in program is too large. Default integers are\n represented using 31 bits, and range from ~1073741824 to 1073741823,\n or from:\n <pre>\t Option.valOf(Int.minInt) to Option.valOf(Int.maxInt)\n </pre>\n \n <pre> val x = 1073741823;\n <i>val x = 1073741823 : int</i>\n \n val x = 1073741824;\n <i>stdIn:2.4-22.7 Error: int constant too large</i>\n \n val x = ~1073741824;\n <i>val x = ~1073741824 : int</i>\n \n val x = ~1073741825;\n <i>stdIn:30.10-30.21 Error: int constant too large</i>\n </pre>\n \n "
},
{
"code": 46,
"msg": "match nonexhaustive",
"verbose": "Insufficient patterns in clause to match against all the possible inputs. This is an error if the flag <code>Compiler.Control.MC.matchNonExhaustiveError</code> is set to true (the default is false), otherwise it is a warning if <code>Compiler.Control.MC.matchNonExhaustiveWarn</code> is set to true. If neither of these flags is true, then the compiler does not complain about nonexhaustive matches.",
"info": "<dd>\n Insufficient patterns in clause to match against all the\n possible inputs. This is an error if the flag\n <code>Compiler.Control.MC.matchNonExhaustiveError</code>\n is set to true (the default is false), otherwise it is a warning if\n <code>Compiler.Control.MC.matchNonExhaustiveWarn</code>\n is set to true. If neither of these flags is true, then\n the compiler does not complain about nonexhaustive matches.\n <pre> fun f 0 = 1\n | f 1 = 1;\n <i>stdIn:1.1-22.12 Error: match nonexhaustive\n 0 => ...\n 1 => ...\n \n val f = fn : int -> int</i>\n </pre>\n \n "
},
{
"code": 47,
"msg": "match redundant",
"verbose": "A pattern is provided that is covered by some earlier pattern. If the compiler flag <code>Compiler.Control.MC.matchRedundantError</code> is set to false (default is true), only a warning message is given. If <code>Compiler.Control.MC.matchRedundantWarn</code> is also false (default is true), no message is generated.",
"info": "<dd>\n A pattern is provided that is covered by some earlier pattern.\n If the compiler flag\n <code>Compiler.Control.MC.matchRedundantError</code>\n is set to false (default is true), only a warning message\n is given. If\n <code>Compiler.Control.MC.matchRedundantWarn</code>\n is also false (default is true), no message is generated.\n <pre> fun f (0, true) = 1\n | f (0, false) = 2\n | f (0, _) = 3\n | f _ = 4;\n <i>stdIn:24.1-27.14 Error: match redundant\n (0,true) => ...\n (0,false) => ...\n --> (0,_) => ...\n _ => ...</i>\n </pre>\n \n "
},
{
"code": 48,
"msg": "match redundant and nonexhaustive",
"verbose": "A pattern is provided that is covered by some earlier pattern, and the set of patterns do not cover all the possible inputs. Whether this message is generated, and its severity (Error or Warning), are controlled by the compiler flags",
"info": "<dd>\n A pattern is provided that is covered by some earlier pattern,\n and the set of patterns do not cover all the possible inputs.\n Whether this message is generated, and its severity (Error or\n Warning), are controlled by the compiler flags\n <pre> <code>Compiler.Control.MC.matchNonExhaustiveError</code>\n <code>Compiler.Control.MC.matchNonExhaustiveWarn</code>\n <code>Compiler.Control.MC.matchRedundantError</code>\n <code>Compiler.Control.MC.matchRedundantWarn</code>\n </pre>\n Example:\n <pre> fun f 1 = 1\n | f 2 = 3\n | f 1 = 4 ;\n <i>stdIn:1.1-24.12 Error: match redundant and nonexhaustive\n 1 => ...\n 2 => ...\n --> 1 => ...</i>\n </pre>\n \n "
},
{
"code": 49,
"msg": "multiple where defs for %",
"verbose": "The <tt>where</tt> clauses of a signature expression must not bind the same type-specification multiple times.",
"info": "<dd>\n The <tt>where</tt> clauses of a signature expression must not\n bind the same type-specification multiple times.\n <pre> signature S = sig\n type t\n end\n where type t = int\n and type t = bool;\n <i>stdIn:1.1-72.20 Error: multiple where defs for t</i>\n </pre>\n or even:\n <pre> signature S = sig\n type t\n end\n where type t = int\n and type t = int;\n <i>stdIn:1.1-76.19 Error: multiple where defs for t</i>\n </pre>\n \n "
},
{
"code": 50,
"msg": "non-constructor applied to argument in pattern",
"verbose": "The value applied to an argument in a pattern is not a constructor.",
"info": "<dd>\n The value applied to an argument in a pattern is not a constructor.\n <pre> fun f (0 0) = true;\n <i>stdIn:17.5-17.19 Error: non-constructor applied to argument in pattern</i>\n </pre>\n \n "
},
{
"code": 51,
"msg": "non-constructor applied to argument in pattern: %",
"verbose": "Same error as [58]. This particular error occurs when the applied value has a name that can be reported.",
"info": "<dd>\n Same error as [58]. This particular error occurs when the applied value has a\n name that can be reported.\n <pre> val a = 0;\n <i>val a = 0 : int</i>\n \n fun f (a 0) = true;\n <i>stdIn:18.5-18.19 Error: non-constructor applied to argument in pattern: a</i>\n </pre>\n \n "
},
{
"code": 52,
"msg": "nonlocal path in structure sharing: %",
"verbose": "A structure participating in a structure <strong>sharing</strong> specification was not declared in the current signature.",
"info": "<dd>\n A structure participating in a structure <strong>sharing</strong>\n specification was not declared in the current signature.\n <pre> signature S = sig\n structure A : sig end\n sharing A = B.C\n end;\n <i>stdIn:41.11-41.18 Error: nonlocal path in structure sharing: B.C</i>\n </pre>\n \n "
},
{
"code": 53,
"msg": "nonlocal path in type sharing: %",
"verbose": "A type participating in a type <strong>sharing</strong> specification was not declared in the current signature.",
"info": "<dd>\n A type participating in a type <strong>sharing</strong> specification\n was not declared in the current signature.\n <pre> signature S = sig\n type t\n sharing type t = B.t\n end;\n <i>stdIn:44.16-44.23 Error: nonlocal path in type sharing: B.t</i>\n </pre>\n \n "
},
{
"code": 54,
"msg": "operator and operand don't agree",
"verbose": "A function (operator) is applied to a value (operand) with a type different than the type expected by the function.",
"info": "<dd>\n A function (operator) is applied to a value (operand) with a type different than\n the type expected by the function.\n <pre> fun f true = 0\n | f false = 1;\n <i>val f = fn : bool -> int</i>\n \n f 3;\n <i>stdIn:25.1-25.4 Error: operator and operand don't agree [literal]\n operator domain: bool\n operand: int\n in expression:\n f 3</i>\n </pre>\n \n "
},
{
"code": 55,
"msg": "operator is not a function",
"verbose": "The value used in operator position is not a function.",
"info": "<dd>\n The value used in operator position is not a function.\n <pre> 3 true;\n <i>stdIn:1.1-19.6 Error: operator is not a function [literal]\n operator: int\n in expression:\n 3 true</i>\n </pre>\n \n "
},
{
"code": 56,
"msg": "or-patterns don't agree",
"verbose": "In a pattern that uses <it>or-ed subpatterns (via <code>|</code>), the type of all the subpatterns must agree.",
"info": "<dd>\n In a pattern that uses <it>or-ed subpatterns (via <code>|</code>), the type\n of all the subpatterns must agree.\n <pre> fun f (0 | 1 | true) = 0;\n <i>stdIn:1.1-21.4 Error: or-patterns don't agree [literal]\n expected: int\n found: bool\n in pattern:\n (1 | true)</i>\n </pre>\n \n </it>"
},
{
"code": 57,
"msg": "out-of-range word literal in pattern: 0w%",
"verbose": "A word literal used in a pattern is larger than the largest representable word.",
"info": "<dd>\n A word literal used in a pattern is larger than the largest representable word.\n <pre> fun f 0w100000000000 = 0\n | f _ = 1;\n <i>stdIn:1.1-27.12 Error: out-of-range word literal in pattern: 0w100000000000</i>\n </pre>\n \n "
},
{
"code": 58,
"msg": "overloaded variable not defined at type",
"verbose": "An overloaded variable is being instantiated at a type for which it has no definition. Typical overloaded variables include numerical operations, overloaded over the numerical types (int, word, etc.)",
"info": "<dd>\n An overloaded variable is being instantiated at a type for which it has no\n definition. Typical overloaded variables include numerical operations,\n overloaded over the numerical types (int, word, etc.)\n <pre> true + true;\n <i>stdIn:19.5 Error: overloaded variable not defined at type\n symbol: +\n type: bool</i>\n </pre>\n \n "
},
{
"code": 59,
"msg": "parameter or result constraints of clauses don't agree",
"verbose": "In a <code><strong>fun</strong></code> declaration, each clause, or rule, separated by <code><strong>|</strong></code> (vertical bar symbol), has to have the same type (both in the type accepted by the clauses, and the type returned by the clauses).",
"info": "<dd>\n In a <code><strong>fun</strong></code> declaration, each clause, or rule, separated by\n <code><strong>|</strong></code> (vertical bar symbol), has to have the same type (both\n in the type accepted by the clauses, and the type returned by the clauses).\n <pre> datatype typeA = A;\n <i>datatype typeA = A</i>\n datatype typeB = B;\n <i>datatype typeB = B</i>\n fun f A = 0\n | f B = 0;\n <i>stdIn:36.1-37.12 Error: parameter or result constraints of clauses don't agree [tycon mismatch]\n this clause: typeB -> 'Z\n previous clauses: typeA -> 'Z\n in declaration:\n f =\n (fn A => 0\n | B => 0)</i>\n </pre>\n \n "
},
{
"code": 60,
"msg": "parentheses illegal around variable in AS pattern",
"verbose": "In an \"as\"-pattern <code><i>pat</i> as <i>pat</i></code>, where the pattern to the left of the \"as\" is a simple variable, the variable must not be wrapped in parentheses.",
"info": "<dd>\n In an \"as\"-pattern <code><i>pat</i> as <i>pat</i></code>, where the pattern to the left\n of the \"as\" is a simple variable, the variable must not be wrapped in parentheses.\n <pre> val ((a) as (b,c)) = (4,5);\n <i>stdIn:19.5-31.2 Error: parentheses illegal around variable in AS pattern</i>\n </pre>\n \n "
},
{
"code": 61,
"msg": "pattern and constraint don't agree",
"verbose": "In a pattern, the type of the pattern and the constaint type of the pattern must agree.",
"info": "<dd>\n In a pattern, the type of the pattern and the constaint type of the pattern must agree.\n <pre> fun f (0:bool)=0;\n <i>stdIn:38.1-38.17 Error: pattern and constraint don't agree [literal]\n pattern: int\n constraint: bool\n in pattern:\n 0 : bool</i>\n </pre>\n \n "
},
{
"code": 62,
"msg": "pattern and expression in val dec don't agree",
"verbose": "In a declaration <code>val <i>pat</i> = <i>exp</i></code>, the type of <i>pat</i> must match the type of <i>exp</i>.",
"info": "<dd>\n In a declaration <code>val <i>pat</i> = <i>exp</i></code>, the type of\n <i>pat</i> must match the type of <i>exp</i>.\n <pre> val s:string = 6;\n <i>stdIn:1.1-18.6 Error: pattern and expression in val dec don't agree [literal]\n pattern: string\n expression: int\n in declaration:\n s : string = 6</i>\n </pre>\n \n "
},
{
"code": 63,
"msg": "pattern and expression in val dec don't agree",
"verbose": "In a declaration <code>val <i>pat</i> = <i>exp</i></code>, the type of <code><i>pat</i></code> must match the type of <code><i>exp</i></code>.",
"info": "<dd>\n In a declaration <code>val <i>pat</i> = <i>exp</i></code>, the type of\n <code><i>pat</i></code> must match the type of <code><i>exp</i></code>.\n <pre> val s:string = 6;\n <i>stdIn:1.1-18.6 Error: pattern and expression in val dec don't agree [literal]\n pattern: string\n expression: int\n in declaration:\n s : string = 6</i>\n </pre>\n \n "
},
{
"code": 64,
"msg": "pattern to left of \"as\" must be variable",
"verbose": "In an \"as\"-pattern <code><i>pat</i> as <i>pat</i></code>, the first pattern must be a simple variable, not a more complex pattern using tuples or data constructors.",
"info": "<dd>\n In an \"as\"-pattern <code><i>pat</i> as <i>pat</i></code>, the first pattern\n must be a simple variable, not a more complex pattern using tuples\n or data constructors.\n <pre> val (a,_) as (_,b) = (7,5);\n <i>stdIn:1.5-18.8 Error: pattern to left of AS must be variable</i>\n </pre>\n \n "
},
{
"code": 65,
"msg": "pattern to left of AS must be variable",
"verbose": "In an \"as\"-pattern <i>pat</i> <tt>as</tt> <i>pat</i>, the first pattern must be a simple variable, not a more complex pattern using tuples or data constructors.",
"info": "<dd>\n In an \"as\"-pattern <i>pat</i> <tt>as</tt> <i>pat</i>, the first pattern\n must be a simple variable, not a more complex pattern using tuples\n or data constructors.\n <pre> val (a,_) as (_,b) = (7,5);\n <i>stdIn:1.5-18.8 Error: pattern to left of AS must be variable</i>\n </pre>\n \n "
},
{
"code": 66,
"msg": "possibly inconsistent structure definitions at: %",
"verbose": "When a signature contains a sharing constraint between two structure-specifications, each of which is specified using a <tt>where</tt> clause, the compiler is unable to calculate whether the structures are compatible. This is a bug in the compiler and will be fixed in a future version.",
"info": "<dd>\n When a signature contains a sharing constraint between\n two structure-specifications, each of which is specified using a <tt>where</tt>\n clause, the compiler is unable to calculate whether the structures\n are compatible. This is a bug in the compiler and will be fixed\n in a future version.\n <pre> signature SIG =\n sig\n structure A : sig end\n structure B : sig structure Z : sig end\n end where Z = A\n structure C : sig structure Z : sig end\n end where Z = A\n sharing B = C\n end;\n \n <i>stdIn:1.1-38.4 Error: possibly inconsistent structure definitions at: B.Z</i>\n </pre>\n \n "
},
{
"code": 67,
"msg": "real constant out of range: %",
"verbose": "A real literal must have an exponent in the proper range for the floating-point representation of the target machine. At present all SML/NJ target machines use IEEE double-precision floating point, so real literals must be in the range ~1.79769313486e308 to 1.79769313486e308.",
"info": "<dd>\n A real literal must have an exponent in the proper range for the\n floating-point representation of the target machine. At present\n all SML/NJ target machines use IEEE double-precision floating point,\n so real literals must be in the range\n ~1.79769313486e308 to 1.79769313486e308.\n <pre> 2e309;\n \n <i>uncaught exception BadReal\n raised at: bignums/realconst.sml:228.54-228.63</i>\n </pre>\n At present, a bug in the compiler raises an exception instead of\n printing the appropriate error message.\n <p>\n \n "
},
{
"code": 68,
"msg": "rebinding data constructor \"%\" as variable",
"verbose": "An identifier bound as a data constructor cannot be rebound as a variable in a pattern.",
"info": "<dd>\n An identifier bound as a data constructor cannot be rebound as a variable\n in a pattern.\n <pre> fun nil x = x;\n <i>stdIn:1.5-2.9 Error: rebinding data constructor \"nil\" as variable</i>\n </pre>\n \n "
},
{
"code": 69,
"msg": "redundant patterns in match",
"verbose": "In a multi-clause pattern match, if one of the later patterns can only match cases that are covered by earlier patterns, then the later pattern is redundant and can never be matched. In SML '97 it is an error to have useless (redundant) patterns.",
"info": "<dd>\n In a multi-clause pattern match, if one of the later patterns can only\n match cases that are covered by earlier patterns, then the\n later pattern is redundant and can never be matched. In SML '97 it\n is an error to have useless (redundant) patterns.\n <pre> 4 handle Match => 5 | e => 6 | Bind => 7;\n <i>stdIn:1.1-20.15 Error: redundant patterns in match\n Match => ...\n e => ...\n --> Bind => ...</i>\n </pre>\n \n "
},
{
"code": 70,
"msg": "redundant where definitions",
"verbose": "The <tt>where</tt> clauses of a signature expression must not bind the same structure-specification to different structures.",
"info": "<dd>\n The <tt>where</tt> clauses of a signature expression must not\n bind the same structure-specification to different structures.\n <pre> signature S1 =\n sig\n structure A : sig type t end\n end\n where A=Int and A=Real;\n <i>stdIn:32.1-36.23 Error: redundant where definitions</i>\n </pre>\n \n "
},
{
"code": 71,
"msg": "rhs of datatype replication not a datatype",
"verbose": "The declaration",
"info": "<dd>\n The declaration\n <pre> datatype <i>id1</i> = datatype <i>id2</i>\n </pre>\n that binds the name <i>id1</i> to the existing datatype <i>id2</i>,\n requires that <i>id2</i> must be a datatype, and not an ordinary type.\n <pre> datatype myint = datatype int;\n <i>stdIn:38.1-38.30 Error: rhs of datatype replication not a datatype</i>\n </pre>\n \n "
},
{
"code": 72,
"msg": "rhs of datatype replication spec not a datatype",
"verbose": "The specification",
"info": "<dd>\n The specification\n <pre> datatype <i>id1</i> = datatype <i>id2</i>\n </pre>\n that binds the name <code><i>id1</i></code> to the existing datatype\n <code><i>id2</i></code>, requires that <code><i>id2</i></code> must be\n a datatype, and not an ordinary type.\n <pre> signature S = sig type t\n datatype d = datatype t\n end;\n <i>stdIn:37.18-40.17 Error: rhs of datatype replication spec not a datatype</i>\n </pre>\n \n "
},
{
"code": 73,
"msg": "right-hand-side of clause doesn't agree with function result type",
"verbose": "The body of (each clause of) a function must have the type specified in the function-result type constraint (if it is present).",
"info": "<dd>\n The body of (each clause of) a function must have the type specified\n in the function-result type constraint (if it is present).\n <pre> fun f(x) : int = \"hello\";\n <i>stdIn:1.1-37.24 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]\n expression: string\n result type: int\n in declaration:\n f = (fn x => \"hello\": int)</i>\n </pre>\n \n "
},
{
"code": 74,
"msg": "sharing structure with a descendent substructure",
"verbose": "A structure cannot share with one of its components.",
"info": "<dd>\n A structure cannot share with one of its components.\n <pre> signature S = sig structure A : sig structure B : sig end end\n sharing A = A.B\n end;\n <i>stdIn:1.1-44.20 Error: Sharing structure with a descendent substructure</i>\n </pre>\n \n "
},
{
"code": 75,
"msg": "structure % defined by partially applied functor",
"verbose": "Functors in SML/NJ may be higher-order, so that the functor F in the example below returns (as its result) another functor, which in turn returns a structure. The result of applying F to an argument cannot, therefore, be bound to a structure name.",
"info": "<dd>\n Functors in SML/NJ may be higher-order, so that the functor F in the\n example below returns (as its result) another functor, which in turn\n returns a structure. The result of applying F to an argument cannot,\n therefore, be bound to a structure name.\n <pre> functor F()() = struct end;\n <i>functor F : <sig></sig></i>\n \n structure S = F();\n <i>stdIn:45.15-45.18 Error: structure S defined by partially applied functor</i>\n </pre>\n \n "
},
{
"code": 76,
"msg": "syntax error found at %",
"verbose": "This message is produced if the parser finds a syntax error and is unable to correct the problem using its built-in heuristics (<a href=#syndel>deletion</a>, <a href=#synins>insertion</a>, or <a href=#synrepl>replacement</a> of tokens). Example:",
"info": "<dd>\n This message is produced if the parser finds a syntax error and is\n unable to correct the problem using its built-in heuristics (<a href=#syndel>deletion</a>, <a href=#synins>insertion</a>, or <a href=#synrepl>replacement</a> of tokens). Example:\n <pre> x andalso val y orelse z;\n <i>stdIn:1.6 Error: syntax error found at VAL</i>\n </pre>\n <i>Note:</i> Error correction in the parser relies on lookahead.\n Different amounts of lookahead are used depending on whether input is\n taken from the interactive toplevel or from a source file. Therefore,\n error messages for the same program can vary depending on circumstances.\n (See also the <a href=#noteins>note on error [78]</a>.)\n <p>\n \n "
},
{
"code": 77,
"msg": "syntax error: deleting %",
"verbose": "This message indicates that the error-correcting parser attempted to rectify a syntax error by deleting (ignoring) some input token(s). <p> For example, let's assume that file <i>delete.sml</i> contains the following code:",
"info": "<dd>\n This message indicates that the error-correcting parser\n attempted to rectify a syntax error by deleting (ignoring) some input\n token(s).\n <p>\n For example, let's assume that file <i>delete.sml</i> contains the\n following code:\n <pre> structure 99 X =\n struct\n val x = 1\n end\n </pre>\n Compiling this file produces:\n <pre> - use \"delete.sml\";\n <i>[opening delete.sml]</i>\n <i>delete.sml:1.11-1.13 Error: syntax error: deleting INT</i>\n </pre>\n <i>Note:</i> Error correction in the parser relies on lookahead.\n Different amounts of lookahead are used depending on whether input is\n taken from the interactive toplevel or from a source file. Therefore,\n error messages for the same program can vary depending on circumstances.\n (See also the <a href=#noteins>note on error [78]</a>.)\n <p>\n \n "
},
{
"code": 78,
"msg": "syntax error: inserting %",
"verbose": "This error message, like the previous one, is generated by SML/NJ's error-correcting parser. It indicates that the parser was able to correct a syntactic error by inserting an additional token. <p> For example, let's assume that file <i>insert.sml</i> contains the following code:",
"info": "<dd>\n This error message, like the previous one, is generated by SML/NJ's\n error-correcting parser. It indicates that the parser was able to\n correct a syntactic error by inserting an additional token.\n <p>\n For example, let's assume that file <i>insert.sml</i> contains the\n following code:\n <pre> let\n val x = 1; y = x + x\n in\n x * y\n end\n </pre>\n Compiling this file produces:\n <pre> - use \"insert.sml\";\n <i>[opening insert.sml]\n insert.sml:2.16 Error: syntax error: inserting VAL</i>\n </pre>\n <a name=noteins><i>Note:</i></a> Error correction in the parser relies\n on lookahead.\n Since the interactive parser cannot use lookahead, it is likely that\n its syntax error messages differ from those that are generated when\n compiling files. For example, typing the contents of\n <i>insert.sml</i> directly into the interactive toplevel produces:\n <pre> let\n val x = 1; y = x + x\n in\n x * y\n end;\n <i>stdIn:2.14-2.19 Error: syntax error: deleting ID EQUALOP ID\n stdIn:2.20-3.3 Error: syntax error: deleting ID ID IN\n stdIn:4.3-4.8 Error: syntax error: deleting ID ASTERISK ID</i>\n </pre>\n \n "
},
{
"code": 79,
"msg": "syntax error: replacing % with %",
"verbose": "The parser found a syntax error and has attempted to fix the problem by replacing some token(s) by some other token(s). <p> For example, let's assume that file <i>replace.sml</i> contains the following code:",
"info": "<dd>\n The parser found a syntax error and has attempted to fix the problem\n by replacing some token(s) by some other token(s).\n <p>\n For example, let's assume that file <i>replace.sml</i> contains the\n following code:\n <pre> fn x = x\n </pre>\n Compiling this file produces:\n <pre> - use \"replace.sml\";\n <i>[opening replace.sml]\n replace.sml:1.6 Error: syntax error: replacing EQUALOP with DARROW</i>\n </pre>\n <i>Note:</i> Error correction in the parser relies on lookahead.\n Different amounts of lookahead are used depending on whether input is\n taken from the interactive toplevel or from a source file. Therefore,\n error messages for the same program can vary depending on circumstances.\n (See also the <a href=#noteins>note on error [78]</a>.)\n <p>\n \n "
},
{
"code": 80,
"msg": "tycon arity for % does not match specified arity",
"verbose": "The arity of a type constructor differs between the definition inside a structure and its declaration in the corresponding signature constraint. <p> Example:",
"info": "<dd>\n The arity of a type constructor differs between the definition inside\n a structure and its declaration in the corresponding signature\n constraint.\n <p>\n Example:\n <pre> signature S = sig type ('a, 'b) t end;\n <i>signature S = sig type ('a,'b) t end</i>\n \n structure S : S = struct\n type 'a t = 'a list\n end;\n <i>stdIn:75.1-77.4 Error: tycon arity for t does not match specified arity</i>\n </pre>\n \n "
},
{
"code": 81,
"msg": "type % must be a datatype",
"verbose": "This message indicates that the signature constraint for a given structure requires some type to be a <strong>datatype</strong> but the structure defines it as different type (i.e., not a datatype). <p> Example:",
"info": "<dd>\n This message indicates that the signature constraint for a given\n structure requires some type to be a <strong>datatype</strong> but the\n structure defines it as different type (i.e., not a datatype).\n <p>\n Example:\n <pre>signature S = sig datatype t = A | B end;\n <i>signature S = sig datatype t = A | B end</i>\n \n structure S : S = struct\n type t = int\n end;\n <i>stdIn:80.1-82.4 Error: type t must be a datatype\n stdIn:80.1-82.4 Error: unmatched constructor specification: A\n stdIn:80.1-82.4 Error: unmatched constructor specification: B</i>\n </pre>\n \n "
},
{
"code": 82,
"msg": "type % must be an equality type",
"verbose": "This error message is issued when the definition for some type inside a structure does not permit equality while the corresponding signature constraint for the structure specifies that type as an <strong>eqtype</strong>. <p> Example:",
"info": "<dd>\n This error message is issued when the definition for some type inside\n a structure does not permit equality while the corresponding signature\n constraint for the structure specifies that type as an\n <strong>eqtype</strong>.\n <p>\n Example:\n <pre> signature S = sig eqtype t end;\n <i>signature S = sig eqtype t end</i>\n \n structure S : S = struct\n type t = int -> int\n end;\n <i>stdIn:86.1-88.4 Error: type t must be an equality type</i>\n </pre>\n \n "
},
{
"code": 83,
"msg": "type constraint of val rec dec is not a function type",
"verbose": "Names that are defined using <strong>val rec</strong> must refer to function values. Therefore, their types must be function types. <p> Example:",
"info": "<dd>\n Names that are defined using <strong>val rec</strong> must refer to\n function values. Therefore, their types must be function types.\n <p>\n Example:\n <pre> val rec f : int = fn x => x;\n <i>stdIn:1.1-79.26 Error: type constraint of val rec dec is not a function type [tycon mismatch]\n constraint: int\n in declaration:\n f = (fn x => x)</i>\n </pre>\n \n "
},
{
"code": 84,
"msg": "type constraints on val rec declaraction [sic] disagree",
"verbose": "This error message occurs when a declaration has the form",
"info": "<dd>\n This error message occurs when a declaration has the form\n <pre> val rec <i>id</i> : <i>ty1</i> = <i>exp : ty2</i>\n </pre>\n and the types <code><i>ty1</i></code> and <code><i>ty2</i></code> disagree.\n <pre> val rec f : int -> int = (fn x => x) : bool -> bool;\n <i>stdIn:1.1-29.30 Error: type constraints on val rec declaraction disagree [tycon mismatch]\n this constraint: bool -> bool\n outer constraints: int -> int\n in declaration:\n f = (fn x => x): bool -> bool</i>\n </pre>\n \n <p>\n \n "
},
{
"code": 85,
"msg": "type constructor % given % arguments, wants %",
"verbose": "A type constructor was used with the wrong number of type arguments. <p> Example:",
"info": "<dd>\n A type constructor was used with the wrong number of type arguments.\n <p>\n Example:\n <pre> type ('a, 'b) t = 'a * 'b;\n <i>type ('a,'b) t = 'a * 'b</i>\n \n type u = (int, bool, real) t;\n <i>stdIn:103.28 Error: type constructor t given 3 arguments, wants 2</i>\n </pre>\n \n "
},
{
"code": 86,
"msg": "type variable % occurs with different equality\n properties in the same scope",
"verbose": "This message indicates that different occurences of the same type variable have inconsistent equality properties. In practice this means that the same name of a type variable was used both with one apostrophe and with two apostrophes. (Note that this would have been ok if the two occurences are clearly separated by scope.) <p> Example:",
"info": "<dd>\n This message indicates that different occurences of the same type\n variable have inconsistent equality properties. In practice this\n means that the same name of a type variable was used both with one\n apostrophe and with two apostrophes. (Note that this would have been\n ok if the two occurences are clearly separated by scope.)\n <p>\n Example:\n <pre> fun f (x: 'a, y: ''a) = (x, y);\n <i>stdIn:118.2-119.12 Error: type variable a occurs with different equality properties in the same scope</i>\n </pre>\n But:\n <pre> fun 'a f (x: 'a) = let\n fun ''a g (y: ''a) = y = y\n in x end;\n <i>val f = fn : 'a -> 'a</i>\n </pre>\n \n "
},
{
"code": 87,
"msg": "type variable in exception spec: %",
"verbose": "Exception declarations in signatures cannot contain type variables. <p> Example:",
"info": "<dd>\n Exception declarations in signatures cannot contain type variables.\n <p>\n Example:\n <pre> signature S = sig\n exception E of 'a list\n end;\n <i>stdIn:135.3-135.26 Error: type variable in exception spec: E</i>\n </pre>\n \n "
},
{
"code": 88,
"msg": "type variable in top level exception type",
"verbose": "Exception definitions at top level cannot contain type variables. <p> Example:",
"info": "<dd>\n Exception definitions at top level cannot contain type variables.\n <p>\n Example:\n <pre> exception E of 'a list;\n <i>stdIn:1.1-135.4 Error: type variable in top level exception type</i>\n </pre>\n \n "
},
{
"code": 89,
"msg": "types of rules don't agree",
"verbose": "The right-hand sides of the rules in a match must agree in type. Matches occur both in <code><strong>case</strong></code>- and in <code><strong>fn</strong></code>-expressions. <p> Examples:",
"info": "<dd>\n The right-hand sides of the rules in a match must agree in type.\n Matches occur both in <code><strong>case</strong></code>- and in\n <code><strong>fn</strong></code>-expressions.\n <p>\n Examples:\n <pre> fn true => false\n | false => 1;\n <i>stdIn:144.1-144.30 Error: types of rules don't agree [literal]\n earlier rule(s): bool -> bool\n this rule: bool -> int\n in rule:\n false => 1</i>\n \n fn x =>\n case x\n of true => false\n | false => 1;\n <i>stdIn:144.6-144.42 Error: types of rules don't agree [literal]\n earlier rule(s): bool -> bool\n this rule: bool -> int\n in rule:\n false => 1</i>\n </pre>\n \n "
},
{
"code": 90,
"msg": "unbound functor signature: %",
"verbose": "This error message is related to SML/NJ's higher-order module extension to Standard ML. The constraint on a functor declaration in some signature uses an undefined functor signature name. <p> Example:",
"info": "<dd>\n This error message is related to SML/NJ's higher-order module\n extension to Standard ML. The constraint on a functor declaration in\n some signature uses an undefined functor signature name.\n <p>\n Example:\n <pre> signature S = sig\n functor F: FS\n end;\n <i>stdIn:145.3-145.17 Error: unbound functor signature: FS</i>\n </pre>\n \n "
},
{
"code": 91,
"msg": "unbound functor: %",
"verbose": "The name of the functor being used is not defined. <p> Example:",
"info": "<dd>\n The name of the functor being used is not defined.\n <p>\n Example:\n <pre> structure S = F ();\n <i>stdIn:147.15-147.19 Error: unbound functor: F</i>\n </pre>\n \n "
},
{
"code": 92,
"msg": "unbound left hand side in where (structure): %",
"verbose": "A <strong>where</strong> specification refers to a structure inside a signature that was not declared there. <p> Example:",
"info": "<dd>\n A <strong>where</strong> specification refers to a structure inside a\n signature that was not declared there.\n <p>\n Example:\n <pre> structure A = struct end;\n <i>structure A : sig end</i>\n \n signature S = sig end;\n <i>signature S = sig end</i>\n \n signature S' = S where B = A;\n <i>stdIn:158.1-158.29 Error: unbound left hand side in where (structure): B</i>\n </pre>\n But:\n <pre> signature S = sig structure B : sig end end;\n <i>signature S = sig structure B : sig end end</i>\n \n signature S' = S where B = A;\n <i>signature S' = sig structure B : sig end end</i>\n </pre>\n \n "
},
{
"code": 93,
"msg": "unbound left hand side in where type: %",
"verbose": "A <code><strong>where type</strong></code> specification refers to a type inside a signature that was not declared there. <p> Example:",
"info": "<dd>\n A <code><strong>where type</strong></code> specification refers to a type inside a\n signature that was not declared there.\n <p>\n Example:\n <pre> type t = int;\n <i>type t = int</i>\n \n signature S = sig end;\n <i>signature S = sig end</i>\n \n signature S' = S where type u = t;\n <i>stdIn:169.1-169.34 Error: unbound left hand side in where type: u</i>\n </pre>\n But:\n <pre> signature S = sig type u end;\n <i>signature S = sig type u end</i>\n \n signature S' = S where type u = t;\n <i>signature S' = sig type u = t end</i>\n </pre>\n \n "
},
{
"code": 94,
"msg": "unbound signature: %",
"verbose": "A signature name is used but it has not been defined; for instance <code>S</code> in the following example:",
"info": "<dd>\n A signature name is used but it has not been defined; for instance\n <code>S</code> in the following example:\n <pre> structure A : S = struct end;\n <i>stdIn:16.15 Error: unbound signature: S</i>\n </pre>\n \n "
},
{
"code": 95,
"msg": "unbound structure: %",
"verbose": "A structure name is used but it has not been defined; for instance <code>B</code> in the following example:",
"info": "<dd>\n A structure name is used but it has not been defined; for instance\n <code>B</code> in the following example:\n <pre> - structure A = B;\n stdIn:2.10 Error: unbound structure: B\n </pre>\n \n "
},
{
"code": 96,
"msg": "unbound type constructor: %",
"verbose": "A type constructor name is used but it has not been defined, for instance <code>t</code> in the following example:",
"info": "<dd>\n A type constructor name is used but it has not been defined, for instance\n <code>t</code> in the following example:\n <pre> val x : t = ();\n <i>stdIn:2.4 Error: unbound type constructor: t</i>\n </pre>\n \n "
},
{
"code": 97,
"msg": "unbound type variable in type declaration: %",
"verbose": "A type variable occurs on the right hand side of a type or datatype declaration, without having been bound as a formal parameter on the left hand side.",
"info": "<dd>\n A type variable occurs on the right hand side of a type or datatype\n declaration, without having been bound as a formal parameter on the\n left hand side.\n <pre> type t = 'a list;\n <i>stdIn:2.5-2.12 Error: unbound type variable in type declaration: 'a</i>\n \n datatype 'a t = A of 'b;\n <i>stdIn:1.1-18.2 Error: unbound type variable in type declaration: 'b</i>\n </pre>\n \n "
},
{
"code": 98,
"msg": "unbound variable or constructor: %",
"verbose": "A value variable or constructor is used without having been defined or bound as a formal parameter.",
"info": "<dd>\n A value variable or constructor is used without having been defined\n or bound as a formal parameter.\n <pre> x;\n <i>stdIn:1.1 Error: unbound variable or constructor: x</i>\n \n fun f x = x+y;\n <i>stdIn:2.8 Error: unbound variable or constructor: y</i>\n </pre>\n \n "
},
{
"code": 99,
"msg": "unresolved flex record (can't tell what fields there are besides %)",
"verbose": "When a flexible record pattern (one containing <code><strong>...</strong></code>) is used, the context must provide enough type information to determine what all the fields are (though not necessarily their types).",
"info": "<dd>\n When a flexible record pattern (one containing <code><strong>...</strong></code>)\n is used, the context must provide enough type information to determine\n what all the fields are (though not necessarily their types).\n <pre> fun f {x,...} = x;\n <i>stdIn:37.1-37.18 Error: unresolved flex record\n (can't tell what fields there are besides #x)</i>\n \n fun f ({x,...} : {x: int, y:bool}) = x;\n <i>val f = fn : {x:int, y:bool} -> int</i>\n </pre>\n If more than one field occurs in the flexible record pattern, then\n a different variant of this error message is generated. See error [100].\n <p>\n \n "
},
{
"code": 100,
"msg": "unresolved flex record (need to know the names of ALL\n the fields in this context)",
"verbose": "The pattern in a pattern match was a <i>flexible record</i>. The pattern omitted some of the record's members and summarized their existence using ellipses (\"<strong>...</strong>\"). But in the given context there was not enough information for the type checker to be able to infer the missing field names.",
"info": "<dd>\n The pattern in a pattern match was a <i>flexible record</i>. The\n pattern omitted some of the record's members and summarized their\n existence using ellipses (\"<strong>...</strong>\"). But in the given\n context there was not enough information for the type checker to be\n able to infer the missing field names.\n <pre> fun f {x,y,...} = (x,y);\n <i>stdIn:118.1-118.24 Error: unresolved flex record (need to know the names of ALL the fields\n in this context)\n type: {x:'Y, y:'X; 'Z}</i>\n </pre>\n \n "
},
{
"code": 101,
"msg": "value type in structure doesn't match signature spec",
"verbose": "A value component of a structure has a different type than that specified in a signature that the structure is matched against.",
"info": "<dd>\n A value component of a structure has a different type than that\n specified in a signature that the structure is matched against.\n <pre> signature S =\n sig\n val x : int\n end;\n <i>signature S = sig val x : int end</i>\n \n structure A : S =\n struct\n val x = true\n end;\n <i>stdIn:21.1-24.4 Error: value type in structure doesn't match signature spec\n name: x\n spec: int\n actual: bool</i>\n </pre>\n \n "
},
{
"code": 102,
"msg": "variable % does not occur in all branches of or-pattern",
"verbose": "SML/NJ supports or-patterns, where a single rule can have several patterns separated with the <code><strong>|</strong></code> symbol. The component patterns of an or-pattern are required to have exactly the same variables with the same types.",
"info": "<dd>\n SML/NJ supports or-patterns, where a single rule can have several patterns\n separated with the <code><strong>|</strong></code> symbol. The\n component patterns of an or-pattern are required to have exactly the\n same variables with the same types.\n <pre> fun f(nil | x::_) = 1;\n <i>stdIn:1.5-2.18 Error: variable x does not occur in all branches of or-pattern</i>\n </pre>\n Here the component patterns are <code>nil</code> and\n <code>x::_</code>, and the variable <code>x</code> doesn't\n occur in the first pattern.\n <p>\n \n "
},
{
"code": 103,
"msg": "variable found where constructor is required: %",
"verbose": "A symbolic path (longid) of length greater than 1 occurring in a pattern must designate a data constructor.",
"info": "<dd>\n A symbolic path (longid) of length greater than 1 occurring in a\n pattern must designate a data constructor.\n <pre> fun f(Int.+) = 3;\n <i>stdIn:1.5-2.12 Error: variable found where constructor is required: Int.+</i>\n </pre>\n \n "
},
{
"code": 104,
"msg": "vector expression type failure",
"verbose": "In a vector expression of the form <code>#[<i>exp<sub>1</sub></i>,exp<sub>2</sub>,...]</code>, all the vector element expressions must be of the same type.",
"info": "<dd>\n In a vector expression of the form\n <code>#[<i>exp<sub>1</sub></i>,exp<sub>2</sub>,...]</code>,\n all the vector element expressions must be of the same type.\n <pre> #[1,true];\n <i>stdIn:1.1-2.5 Error: vector expression type failure [literal]</i>\n \n fun f(x:int) = #[x,true];\n <i>stdIn:2.11-2.20 Error: vector expression type failure [tycon mismatch]</i>\n </pre>\n \n "
},
{
"code": 105,
"msg": "vector pattern type failure",
"verbose": "In a vector pattern of the form <code>#[<i>pat<sub>1</sub></i>,pat<sub>2</sub>,...]</code>, all the vector element patterns must be of the same type.",
"info": "<dd>\n In a vector pattern of the form\n <code>#[<i>pat<sub>1</sub></i>,pat<sub>2</sub>,...]</code>,\n all the vector element patterns must be of the same type.\n <pre> fun f(#[x:int,y:bool]) = (x + 1; not y);\n <i>stdIn:1.1-2.35 Error: vector pattern type failure [tycon mismatch]</i>\n </pre>\n \n "
},
{
"code": 106,
"msg": "where defn applied to definitional spec",
"verbose": "SML/NJ does not allow multiple definitions of a structure in a signature (one through a definitional spec, another through a <code><strong>where</strong></code> clause).",
"info": "<dd>\n SML/NJ does not allow multiple definitions of a structure in a signature\n (one through a definitional spec, another through a\n <code><strong>where</strong></code> clause).\n <pre> structure A = struct end;\n <i>structure A : sig end</i>\n \n signature S =\n sig\n structure X : sig end = A\n end\n where X = A;\n <i>stdIn:27.1-31.12 Error: where defn applied to definitional spec</i>\n </pre>\n \n "
},
{
"code": 107,
"msg": "where type definition has wrong arity: %",
"verbose": "The arity implied by a <code><strong>where type</strong></code> definition must agree with the arity in type specification that it applies to.",
"info": "<dd>\n The arity implied by a <code><strong>where type</strong></code>\n definition must agree with the arity in type specification that\n it applies to.\n <pre> signature S =\n sig\n type 'a t\n end\n where type t = int;\n <i>stdIn:1.1-26.19 Error: where type definition has wrong arity: t</i>\n </pre>\n \n "
},
{
"code": 108,
"msg": "where type defn applied to definitional spec: %",
"verbose": "SML/NJ does not allow multiple definitions of a type in a signature (one through a definitional spec, another through a <code><strong>where type</strong></code> clause).",
"info": "<dd>\n SML/NJ does not allow multiple definitions of a type in a signature\n (one through a definitional spec, another through a\n <code><strong>where type</strong></code> clause).\n <pre> signature S =\n sig\n type t = int\n end\n where type t = int;\n <i>stdIn:1.1-22.19 Error: where type defn applied to definitional spec: t</i>\n </pre>\n \n "
},
{
"code": 109,
"msg": "withtype not allowed in datatype replication",
"verbose": "One can't attach a <code><strong>withtype</strong></code> clause to a datatype replication declaration or specification.",
"info": "<dd>\n One can't attach a <code><strong>withtype</strong></code> clause to a\n datatype replication declaration or specification.\n <pre> datatype t = A;\n <i>datatype t = A</i>\n \n datatype s = datatype t\n withtype u = s list;\n <i>stdIn:37.1-38.20 Error: withtype not allowed in datatype replication</i>\n </pre>\n \n "
},
{
"code": 110,
"msg": "word constant too large",
"verbose": "Word constants (by default Word31.word) are limited to values less than <code>0w2147483648</code> (<code>0wx80000000</code>). Similarly for word literals of type Word32.word (bound <code>0w4294967296</code>) and Word8.word (bound 0w256).",
"info": "<dd>\n Word constants (by default Word31.word) are limited to values less\n than <code>0w2147483648</code> (<code>0wx80000000</code>). Similarly\n for word literals of type Word32.word (bound <code>0w4294967296</code>)\n and Word8.word (bound 0w256).\n <pre> 0w2147483648;\n <i>stdIn:1.1-18.3 Error: word constant too large</i>\n 0wx80000000;\n <i>stdIn:1.1-18.2 Error: word constant too large</i>\n \n 0w4294967296 : Word32.word;\n <i>stdIn:25.1-25.13 Error: word constant too large</i>\n 0wx100000000 : Word32.word;\n <i>stdIn:23.1-23.13 Error: word constant too large</i>\n \n 0w256: Word8.word;\n <i>stdIn:1.1-1.6 Error: word constant too large</i>\n 0wx100 : Word8.word;\n <i>stdIn:1.1-24.2 Error: word constant too large</i>\n </pre>\n "
}
]
ERROR_MSGS = [re.compile(re.escape(m["msg"]).replace("%", ".+?") + r"( \[.+\])?") for m in ERRORS_INFO]
def find_error(msg: str) -> Optional[int]:
# FIXME
for i, r in enumerate(ERROR_MSGS):
if r.match(msg):
return i
return None
def prettify_error_message(msg: str) -> str:
msg += "\n"
msg = re.sub(r"^stdIn:.*?\s", "", msg)
lines = msg.splitlines()
first_line = lines[0]
if m := re.match(r"^Error: (.*?)(\s+\[.*\])?$", first_line):
index = find_error(m.group(1))
if index is not None:
msg += ERRORS_INFO[index]["verbose"] + "\n"
return msg
class SMLNJKernel(Kernel):
implementation = "SML/NJ"
implementation_version = "0.0.1"
language_info = {
"name": "SML/NJ",
"codemirror_mode": "fsharp",
"mimetype": "text/plain",
"file_extension": ".sml",
}
@property
def language_version(self) -> str:
if self._language_version is None:
self._language_version = check_output(["sml", ""]).decode("utf-8")
return self._language_version
@property
def banner(self) -> str:
return f"Simple SML/NJ Kernel {self.language_version}"
def __init__(self, **kwargs):
Kernel.__init__(self, **kwargs)
self._language_version = None
self._start_smlnj()
def _start_smlnj(self):
sig = signal.signal(signal.SIGINT, signal.SIG_DFL)
try:
self.smlnjwrapper = REPLWrapper(
f"sml -Cparser.primary-prompt={PRIMARY_PROMPT}",
# f"sml -Cparser.primary-prompt={PRIMARY_PROMPT} -Cparser.seconday-prompt={SECONDARY_PROMPT}",
"(\n|^)" + PRIMARY_PROMPT,
"(\n|^)" + SECONDARY_PROMPT,
)
finally:
signal.signal(signal.SIGINT, sig)
def do_complete(self, code: str, cursor_pos: int) -> Dict[str, Any]:
m = REGEX_WORD.search(code[:cursor_pos])
if m is not None:
keyword = m.group(1)
matches = [s for s in SML_KEYWORDS if s.startswith(keyword)]
if matches:
return {
"status": "ok",
"matches": matches,
"cursor_start": cursor_pos - len(keyword),
"cursor_end": cursor_pos,
"metadata": {},
}
return {
"status": "ok",
"matches": [],
"cursor_start": cursor_pos,
"cursor_end": cursor_pos,
"metadata": {},
}
def do_is_complete(self, code: str) -> Dict[str, Any]:
stripped = code.rstrip()
if not stripped:
return {
"status": "complete",
}
elif stripped.endswith("*)") or stripped.endswith(";"):
return {
"status": "unknown",
}
else:
return {
"status": "incomplete",
"indent": "",
}
def stdout_print(self, text: str) -> None:
stream_content = {"name": "stdout", "text": text}
self.send_msg("stream", stream_content)
def stderr_print(self, text: str) -> None:
self.send_msg("stream", {"name": "stderr", "text": text})
def send_msg(self, message_type: str, content: dict) -> None:
self.send_response(self.iopub_socket, message_type, content)
def do_execute(
self,
code: str,
silent,
store_history: bool = True,
user_expressions=None,
allow_stdin: bool = False,
) -> Dict[str, Any]:
code = crlf_pat.sub(" ", code.strip())
if not code:
return {
"status": "ok",
"execution_count": self.execution_count,
"payload": [],
"user_expressions": {},
}
interrupted = False
try:
output = self.smlnjwrapper.run_command(code)
except KeyboardInterrupt:
self.smlnjwrapper.child.sendintr()
interrupted = True
self.smlnjwrapper._expect_prompt()
output = self.smlnjwrapper.get_output()
except pexpect.EOF:
output = self.smlnjwrapper.get_output() + "Restarting SML/NJ"
self._start_smlnjang()
except ValueError as e:
# Continuation prompt found - input was incomplete
self.stderr_print(e.args[0])
return {"status": "error", "execution_count": self.execution_count}
if not silent and output is not None:
if output.startswith("stdIn"):
self.stderr_print(prettify_error_message(output))
# self.send_msg("display_data", {"data": {"text/html": f"<p style='color:red;'>{html.escape(output)}</p>"}, "metadata": {}})
return {"status": "error", "execution_count": self.execution_count}
self.stdout_print(output)
if interrupted:
return {"status": "abort", "execution_count": self.execution_count}
return {
"status": "ok",
"execution_count": self.execution_count,
"payload": [],
"user_expressions": {},
}
if __name__ == "__main__":
IPKernelApp.launch_instance(kernel_class=SMLNJKernel)