-
Notifications
You must be signed in to change notification settings - Fork 15
/
builtIn.smli
3242 lines (3031 loc) · 126 KB
/
builtIn.smli
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
(*
* Licensed to Julian Hyde under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Julian Hyde licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*)
Sys.set ("lineWidth", 78);
> val it = () : unit
Sys.set ("printLength", 64);
> val it = () : unit
Sys.set ("stringDepth", ~1);
> val it = () : unit
(* Structures -------------------------------------------------- *)
General;
> val it = {ignore=fn,`op o`=fn}
> : {ignore:'a -> unit, `op o`:('b -> 'c) * ('d -> 'b) -> 'd -> 'c}
Int;
> val it =
> {abs=fn,compare=fn,div=fn,fromInt=fn,fromLarge=fn,fromString=fn,max=fn,
> maxInt=SOME 2147483647,min=fn,minInt=SOME 2147483647,mod=fn,
> precision=SOME 32,quot=fn,rem=fn,sameSign=fn,sign=fn,toInt=fn,toLarge=fn,
> toString=fn}
> : {abs:int -> int, compare:int * int -> order, div:int * int -> int,
> fromInt:int -> int, fromLarge:int -> int, fromString:string -> int option,
> max:int * int -> int, maxInt:int option, min:int * int -> int,
> minInt:int option, mod:int * int -> int, precision:int option,
> quot:int * int -> int, rem:int * int -> int, sameSign:int * int -> bool,
> sign:int -> int, toInt:int -> int, toLarge:int -> int,
> toString:int -> string}
Interact;
> val it = {use=fn,useSilently=fn}
> : {use:string -> unit, useSilently:string -> unit}
List;
> val it =
> {all=fn,app=fn,at=fn,collate=fn,concat=fn,drop=fn,exists=fn,filter=fn,
> find=fn,foldl=fn,foldr=fn,getItem=fn,hd=fn,last=fn,length=fn,map=fn,
> mapPartial=fn,nil=[],nth=fn,null=fn,`op @`=fn,partition=fn,rev=fn,
> revAppend=fn,tabulate=fn,take=fn,tl=fn}
> : {all:('a -> bool) -> 'a list -> bool, app:('b -> unit) -> 'b list -> unit,
> at:'c list * 'c list -> 'c list,
> collate:('d * 'd -> order) -> 'd list * 'd list -> order,
> concat:'e list list -> 'e list, drop:'f list * int -> 'f list,
> exists:('g -> bool) -> 'g list -> bool,
> filter:('h -> bool) -> 'h list -> 'h list,
> find:('i -> bool) -> 'i list -> 'i option,
> foldl:('j * 'k -> 'k) -> 'k -> 'j list -> 'k,
> foldr:('l * 'm -> 'm) -> 'm -> 'l list -> 'm,
> getItem:'n list -> ('n * 'n list) option, hd:'o list -> 'o,
> last:'p list -> 'p, length:'q list -> int,
> map:('r -> 's) -> 'r list -> 's list,
> mapPartial:('t -> 'u option) -> 't list -> 'u list, nil:'v list,
> nth:'w list * int -> 'w, null:'x list -> bool,
> `op @`:'y list * 'y list -> 'y list,
> partition:('z -> bool) -> 'z list -> 'z list * 'z list,
> rev:'ba list -> 'ba list, revAppend:'bb list * 'bb list -> 'bb list,
> tabulate:int * (int -> 'bc) -> 'bc list, take:'bd list * int -> 'bd list,
> tl:'be list -> 'be list}
List.rev;
> val it = fn : 'a list -> 'a list
List.rev [1,2,3];
> val it = [3,2,1] : int list
Math;
> val it =
> {acos=fn,asin=fn,atan=fn,atan2=fn,cos=fn,cosh=fn,e=2.7182817,exp=fn,ln=fn,
> log10=fn,pi=3.1415927,pow=fn,sin=fn,sinh=fn,sqrt=fn,tan=fn,tanh=fn}
> : {acos:real -> real, asin:real -> real, atan:real -> real,
> atan2:real * real -> real, cos:real -> real, cosh:real -> real, e:real,
> exp:real -> real, ln:real -> real, log10:real -> real, pi:real,
> pow:real * real -> real, sin:real -> real, sinh:real -> real,
> sqrt:real -> real, tan:real -> real, tanh:real -> real}
Option;
> val it =
> {app=fn,compose=fn,composePartial=fn,filter=fn,getOpt=fn,isSome=fn,join=fn,
> map=fn,mapPartial=fn,valOf=fn}
> : {app:('a option -> unit) -> 'a option -> unit,
> compose:('b -> 'c) * ('d -> 'b option) -> 'd -> 'c option,
> composePartial:('e -> 'f option) * ('g -> 'e option) -> 'g -> 'f option,
> filter:('h -> bool) -> 'h -> 'h option, getOpt:'i option * 'i -> 'i,
> isSome:'j option -> bool, join:'k option option -> 'k option,
> map:('l -> 'm) -> 'l option -> 'm option,
> mapPartial:('n -> 'o option) -> 'n option -> 'o option,
> valOf:'p option -> 'p}
Option.compose;
> val it = fn : ('a -> 'b) * ('c -> 'a option) -> 'c -> 'b option
String;
> val it =
> {concat=fn,concatWith=fn,explode=fn,extract=fn,implode=fn,isPrefix=fn,
> isSubstring=fn,isSuffix=fn,map=fn,maxSize=2147483647,size=fn,str=fn,sub=fn,
> substring=fn,translate=fn}
> : {concat:string list -> string, concatWith:string -> string list -> string,
> explode:string -> char list, extract:string * int * int option -> string,
> implode:char list -> string, isPrefix:string -> string -> bool,
> isSubstring:string -> string -> bool, isSuffix:string -> string -> bool,
> map:(char -> char) -> string -> string, maxSize:int, size:string -> int,
> str:char -> string, sub:string * int -> char,
> substring:string * int * int -> string,
> translate:(char -> string) -> string -> string}
Real;
> val it =
> {abs=fn,ceil=fn,checkFloat=fn,compare=fn,copySign=fn,floor=fn,fromInt=fn,
> fromManExp=fn,fromString=fn,isFinite=fn,isNan=fn,isNormal=fn,max=fn,
> maxFinite=3.4028235E38,min=fn,minNormalPos=1.1754944E~38,minPos=1.4E~45,
> negInf=~inf,posInf=inf,precision=24,radix=2,realCeil=fn,realFloor=fn,
> realMod=fn,realRound=fn,realTrunc=fn,rem=fn,round=fn,sameSign=fn,sign=fn,
> signBit=fn,split=fn,toManExp=fn,toString=fn,trunc=fn,unordered=fn}
> : {abs:real -> real, ceil:real -> int, checkFloat:real -> real,
> compare:real * real -> order, copySign:real * real -> real,
> floor:real -> int, fromInt:int -> real,
> fromManExp:{exp:int, man:real} -> real, fromString:string -> real option,
> isFinite:real -> bool, isNan:real -> bool, isNormal:real -> bool,
> max:real * real -> real, maxFinite:real, min:real * real -> real,
> minNormalPos:real, minPos:real, negInf:real, posInf:real, precision:int,
> radix:int, realCeil:real -> real, realFloor:real -> real,
> realMod:real -> real, realRound:real -> real, realTrunc:real -> real,
> rem:real * real -> real, round:real -> int, sameSign:real * real -> bool,
> sign:real -> int, signBit:real -> bool,
> split:real -> {frac:real, whole:real},
> toManExp:real -> {exp:int, man:real}, toString:real -> string,
> trunc:real -> int, unordered:real * real -> bool}
Relational;
> val it =
> {count=fn,exists=fn,iterate=fn,max=fn,min=fn,notExists=fn,only=fn,sum=fn}
> : {count:'a list -> int, exists:'b list -> bool,
> iterate:'c list -> ('c list * 'c list -> 'c list) -> 'c list,
> max:'d list -> 'd, min:'e list -> 'e, notExists:'f list -> bool,
> only:'g list -> 'g, sum:'h list -> 'h}
(* Operators --------------------------------------------------- *)
2 + 3;
> val it = 5 : int
2 + 3 * 4;
> val it = 14 : int
Sys.plan ();
> val it =
> "apply2(fnValue +, constant(2), apply2(fnValue *, constant(3), constant(4)))"
> : string
14 div 3;
> val it = 4 : int
14 div ~3;
> val it = ~5 : int
from (i, j) in [(14, 3), (~14, 3), (14, ~3), (~14, ~3)]
where (i div j) <> Int.`div` (i, j)
orelse (i mod j) <> Int.`mod` (i, j);
> val it = [] : {i:int, j:int} list
fn x => x + 1;
> val it = fn : int -> int
Sys.plan ();
> val it = "match(x, apply2(fnValue +, get(name x), constant(1)))" : string
val nan = Real.posInf / Real.posInf;
> val nan = nan : real
(* Datatypes --------------------------------------------------- *)
(*) datatype option
SOME 1;
> val it = SOME 1 : int option
NONE;
> val it = NONE : 'a option
NONE = NONE;
> val it = true : bool
NONE = SOME 1;
> val it = false : bool
SOME "a" = NONE;
> val it = false : bool
SOME (SOME true);
> val it = SOME (SOME true) : bool option option
SOME (SOME [1,2,3]);
> val it = SOME (SOME [1,2,3]) : int list option option
SOME (SOME {a=1, b=true});
> val it = SOME (SOME {a=1,b=true}) : {a:int, b:bool} option option
(* Top-level environment --------------------------------------- *)
(* A few functions and operators belong to signatures but can be
used unqualified. For example, "hd" is shorthand for "List.hd".
The following are all of the top-level functions and operators
defined by Standard ML. *)
(* "val ! : 'a ref -> 'a" maps to "General.!" *)
(*) TODO !;
(* "val := : 'a ref * 'a -> unit" maps to "General.:=" *)
(*) TODO :=;
(* "val @ : ('a list * 'a list) -> 'a list" maps to "List.@" *)
(*) TODO @;
(* "val ^ : string * string -> string" maps to "String.^" *)
(*) TODO ^;
(* "val app : ('a -> unit) -> 'a list -> unit" maps to "List.app" *)
app;
> val it = fn : ('a -> unit) -> 'a list -> unit
(* "val before : 'a * unit -> 'a" maps to "General.before" *)
(*) TODO before;
(* "val ceil : real -> int" maps to "Real.ceil" *)
ceil;
> val it = fn : real -> int
(* "val chr : int -> char" maps to "Char.chr" *)
(*) TODO chr;
(* "val concat : string list -> string" maps to "String.concat" *)
concat;
> val it = fn : string list -> string
(* "val exnMessage : exn -> string" maps to "General.exnMessage" *)
(*) TODO exnMessage;
(* "val exnName : exn -> string" maps to "General.exnName" *)
(*) TODO exnName;
(* "val explode : string -> char list" maps to "String.explode" *)
explode;
> val it = fn : string -> char list
(* "val floor : real -> int" maps to "Real.floor" *)
floor;
> val it = fn : real -> int
(* "val foldl : ('a*'b->'b)-> 'b -> 'a list -> 'b" maps to "List.foldl" *)
foldl;
> val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
(* "val foldr : ('a*'b->'b)-> 'b -> 'a list -> 'b" maps to "List.foldr" *)
foldr;
> val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
(* "val getOpt : ('a option * 'a) -> 'a" maps to "Option.getOpt" *)
getOpt;
> val it = fn : 'a option * 'a -> 'a
(* "val hd : 'a list -> 'a" maps to "List.hd" *)
hd;
> val it = fn : 'a list -> 'a
(* "val ignore : 'a -> unit" maps to "General.ignore" *)
ignore;
> val it = fn : 'a -> unit
(* "val implode : char list -> string" maps to "String.implode" *)
implode;
> val it = fn : char list -> string
(* "val isSome : 'a option -> bool" maps to "Option.isSome" *)
isSome;
> val it = fn : 'a option -> bool
(* "val length : 'a list -> int" maps to "List.length" *)
length;
> val it = fn : 'a list -> int
(* "val map : ('a -> 'b) -> 'a list -> 'b list" maps to "List.map" *)
map;
> val it = fn : ('a -> 'b) -> 'a list -> 'b list
(* "val not : bool -> bool" maps to "Bool.not" *)
not;
> val it = fn : bool -> bool
(* "val null : 'a list -> bool" maps to "List.null" *)
null;
> val it = fn : 'a list -> bool
(* "val o : ('a->'b) * ('c->'a) -> 'c->'b" maps to "General.o" *)
(*) TODO o;
(* "val ord : char -> int" maps to "Char.ord" *)
(*) TODO ord;
(* "val print : string -> unit" maps to "TextIO.print" *)
(*) TODO print;
(* "val real : int -> real" maps to "Real.fromInt" *)
real;
> val it = fn : int -> real
(* "val ref : 'a -> 'a ref" maps to "primitive" *)
(*) TODO ref;
(* "val rev : 'a list -> 'a list" maps to "List.rev" *)
rev;
> val it = fn : 'a list -> 'a list
(* "val round : real -> int" maps to "Real.round" *)
round;
> val it = fn : real -> int
(* "val size : string -> int" maps to "String.size" *)
size;
> val it = fn : string -> int
(* "val str : char -> string" maps to "String.str" *)
str;
> val it = fn : char -> string
(* "val substring : string * int * int -> string" maps to "String.substring" *)
substring;
> val it = fn : string * int * int -> string
(* "val tl : 'a list -> 'a list" maps to "List.tl" *)
tl;
> val it = fn : 'a list -> 'a list
(* "val trunc : real -> int" maps to "Real.trunc" *)
trunc;
> val it = fn : real -> int
(* "val use : string -> unit" maps to "implementation dependent" *)
use;
> val it = fn : string -> unit
(* "val valOf : 'a option -> 'a" maps to "Option.valOf" *)
valOf;
> val it = fn : 'a option -> 'a
(* "val vector : 'a list -> 'a vector" maps to "Vector.fromList" *)
vector;
> val it = fn : 'a list -> 'a vector
(* General ----------------------------------------------------- *)
(*) op o - function composition
val plusOne = fn x => x + 1;
> val plusOne = fn : int -> int
val timesTwo = fn x => x * 2;
> val timesTwo = fn : int -> int
val plusThree = fn x => x + 3;
> val plusThree = fn : int -> int
plusOne o timesTwo;
> val it = fn : int -> int
(plusOne o timesTwo) 3;
> val it = 7 : int
plusOne o timesTwo o plusThree;
> val it = fn : int -> int
((plusOne o timesTwo) o plusThree) 3;
> val it = 13 : int
(plusOne o (timesTwo o plusThree)) 3;
> val it = 13 : int
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue o, argCode tuple(get(name plusOne), apply(fnValue o, argCode tuple(get(name timesTwo), get(name plusThree))))), argCode constant(3))"
> : string
ignore;
> val it = fn : 'a -> unit
ignore (1 + 2);
> val it = () : unit
Sys.plan ();
> val it =
> "apply(fnValue General.ignore, argCode apply2(fnValue +, constant(1), constant(2)))"
> : string
(* Interact ---------------------------------------------------- *)
(*) use - load source from a file
Interact.use;
> val it = fn : string -> unit
use;
> val it = fn : string -> unit
(* String ------------------------------------------------------ *)
(*) val maxSize : int
String.maxSize;
> val it = 2147483647 : int
Sys.plan ();
> val it = "constant(2147483647)" : string
(*) val size : string -> int
String.size;
> val it = fn : string -> int
String.size "abc";
> val it = 3 : int
String.size "";
> val it = 0 : int
Sys.plan ();
> val it = "apply(fnValue String.size, argCode constant())" : string
(*) val sub : string * int -> char
String.sub;
> val it = fn : string * int -> char
String.sub("abc", 0);
> val it = #"a" : char
String.sub("abc", 2);
> val it = #"c" : char
String.sub("abc", 20);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.22
String.sub("abc", 3);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.21
String.sub("abc", ~1);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.22
Sys.plan ();
> val it = "apply2(fnValue String.sub, constant(abc), constant(-1))" : string
(*) val extract: string * int * int option -> string
String.extract;
> val it = fn : string * int * int option -> string
String.extract("abc", 1, NONE);
> val it = "bc" : string
String.extract("abc", 1, SOME 2);
> val it = "bc" : string
String.extract("abc", 3, NONE);
> val it = "" : string
String.extract("abc", 3, SOME 0);
> val it = "" : string
String.extract("abc", 4, NONE);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.31
String.extract("abc", ~1, NONE);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.32
String.extract("abc", 4, SOME 2);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.33
String.extract("abc", ~1, SOME 2);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.34
String.extract("abc", 1, SOME ~1);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.34
String.extract("abc", 1, SOME 99);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.34
Sys.plan ();
> val it =
> "apply3(fnValue String.extract, constant(abc), constant(1), apply(fnValue tyCon, argCode constant(99)))"
> : string
(*) val substring : string * int * int -> string
String.substring;
> val it = fn : string * int * int -> string
String.substring("hello, world", 2, 7);
> val it = "llo, wo" : string
String.substring("hello, world", 0, 1);
> val it = "h" : string
String.substring("hello", 5, 0);
> val it = "" : string
String.substring("hello", 1, 4);
> val it = "ello" : string
String.substring("", 0, 0);
> val it = "" : string
String.substring("hello", ~1, 0);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.33
String.substring("hello", 1, ~1);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.33
String.substring("hello", 1, 5);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.32
Sys.plan ();
> val it =
> "apply3(fnValue String.substring, constant(hello), constant(1), constant(5))"
> : string
(*) val ^ : string * string -> string
"a" ^ "bc";
> val it = "abc" : string
"a" ^ "";
> val it = "a" : string
"a" ^ "bc" ^ "" ^ "def";
> val it = "abcdef" : string
Sys.plan ();
> val it =
> "apply2(fnValue ^, apply2(fnValue ^, apply2(fnValue ^, constant(a), constant(bc)), constant()), constant(def))"
> : string
(*) val concat : string list -> string
String.concat;
> val it = fn : string list -> string
String.concat ["a", "bc", "def"];
> val it = "abcdef" : string
String.concat ["a"];
> val it = "a" : string
String.concat [];
> val it = "" : string
Sys.plan ();
> val it = "apply(fnValue String.concat, argCode tuple)" : string
(*) val concatWith : string -> string list -> string
String.concatWith;
> val it = fn : string -> string list -> string
String.concatWith "," ["a", "bc", "def"];
> val it = "a,bc,def" : string
String.concatWith "," ["a"];
> val it = "a" : string
String.concatWith "," ["", ""];
> val it = "," : string
String.concatWith "," [];
> val it = "" : string
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue String.concatWith, argCode constant(,)), argCode tuple)"
> : string
(*) val str : char -> string
String.str;
> val it = fn : char -> string
String.str #"a";
> val it = "a" : string
Sys.plan ();
> val it = "apply(fnValue String.str, argCode constant(a))" : string
(*) val implode : char list -> string
String.implode;
> val it = fn : char list -> string
String.implode [#"a", #"b", #"c"];
> val it = "abc" : string
String.implode [];
> val it = "" : string
Sys.plan ();
> val it = "apply(fnValue String.implode, argCode tuple)" : string
(*) val explode : string -> char list
String.explode;
> val it = fn : string -> char list
String.explode "abc";
> val it = [#"a",#"b",#"c"] : char list
String.explode "";
> val it = [] : char list
Sys.plan ();
> val it = "apply(fnValue String.explode, argCode constant())" : string
(*) val map : (char -> char) -> string -> string
String.map;
> val it = fn : (char -> char) -> string -> string
String.map (fn c => if c = #"a" then #"A" else if c = #"c" then #"C" else c) "abc";
> val it = "AbC" : string
String.map (fn c => if c = #"a" then #"A" else if c = #"c" then #"C" else c) "";
> val it = "" : string
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue String.map, argCode match(c, apply(fnCode match(true, constant(A), _, apply(fnCode match(true, constant(C), _, get(name c)), argCode apply2(fnValue =, get(name c), constant(c)))), argCode apply2(fnValue =, get(name c), constant(a))))), argCode constant())"
> : string
(*) val translate : (char -> string) -> string -> string
String.translate;
> val it = fn : (char -> string) -> string -> string
String.translate (fn c => if c = #"a" then "AA" else if c = #"c" then "CCC" else "-") "abc";
> val it = "AA-CCC" : string
String.translate (fn c => if c = #"a" then "AA" else if c = #"c" then "CCC" else "-") "";
> val it = "" : string
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue String.translate, argCode match(c, apply(fnCode match(true, constant(AA), _, apply(fnCode match(true, constant(CCC), _, constant(-)), argCode apply2(fnValue =, get(name c), constant(c)))), argCode apply2(fnValue =, get(name c), constant(a))))), argCode constant())"
> : string
(*) val tokens : (char -> bool) -> string -> string list
(*) val fields : (char -> bool) -> string -> string list
(*) val isPrefix : string -> string -> bool
String.isPrefix;
> val it = fn : string -> string -> bool
String.isPrefix "he" "hello";
> val it = true : bool
String.isPrefix "el" "hello";
> val it = false : bool
String.isPrefix "lo" "hello";
> val it = false : bool
String.isPrefix "bonjour" "hello";
> val it = false : bool
String.isPrefix "el" "";
> val it = false : bool
String.isPrefix "" "hello";
> val it = true : bool
String.isPrefix "" "";
> val it = true : bool
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue String.isPrefix, argCode constant()), argCode constant())"
> : string
(*) val isSubstring : string -> string -> bool
String.isSubstring;
> val it = fn : string -> string -> bool
String.isSubstring "he" "hello";
> val it = true : bool
String.isSubstring "el" "hello";
> val it = true : bool
String.isSubstring "lo" "hello";
> val it = true : bool
String.isSubstring "bonjour" "hello";
> val it = false : bool
String.isSubstring "el" "";
> val it = false : bool
String.isSubstring "" "hello";
> val it = true : bool
String.isSubstring "" "";
> val it = true : bool
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue String.isSubstring, argCode constant()), argCode constant())"
> : string
(*) val isSuffix : string -> string -> bool
String.isSuffix;
> val it = fn : string -> string -> bool
String.isSuffix "he" "hello";
> val it = false : bool
String.isSuffix "el" "hello";
> val it = false : bool
String.isSuffix "lo" "hello";
> val it = true : bool
String.isSuffix "bonjour" "hello";
> val it = false : bool
String.isSuffix "el" "";
> val it = false : bool
String.isSuffix "" "hello";
> val it = true : bool
String.isSuffix "" "";
> val it = true : bool
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue String.isSuffix, argCode constant()), argCode constant())"
> : string
(*) val compare : string * string -> order
(*) val collate : (char * char -> order) -> string * string -> order
(*) val < : string * string -> bool
(*) val <= : string * string -> bool
(*) val > : string * string -> bool
(*) val >= : string * string -> bool
(*) val scan : (char, 'a) StringCvt.reader
(*) -> (string, 'a) StringCvt.reader
(*) val toCString : string -> String.string
(*) val fromCString : String.string -> string option
(* List -------------------------------------------------------- *)
(*) val nil : 'a list
List.nil;
> val it = [] : 'a list
Sys.plan ();
> val it = "constant([])" : string
(*) val null : 'a list -> bool
List.null;
> val it = fn : 'a list -> bool
List.null [];
> val it = true : bool
List.null [1];
> val it = false : bool
Sys.plan ();
> val it = "apply(fnValue List.null, argCode tuple(constant(1)))" : string
(*) val length : 'a list -> int
List.length;
> val it = fn : 'a list -> int
List.length [];
> val it = 0 : int
List.length [1,2];
> val it = 2 : int
Sys.plan ();
> val it = "apply(fnValue List.length, argCode tuple(constant(1), constant(2)))"
> : string
(*) val @ : 'a list * 'a list -> 'a list
List.at;
> val it = fn : 'a list * 'a list -> 'a list
List.at ([1], [2, 3]);
> val it = [1,2,3] : int list
List.at ([1], []);
> val it = [1] : int list
List.at ([], [2]);
> val it = [2] : int list
List.at ([], []);
> val it = [] : 'a list
Sys.plan ();
> val it = "apply2(fnValue List.at, tuple, tuple)" : string
[1] @ [2, 3];
> val it = [1,2,3] : int list
[] @ [];
> val it = [] : 'a list
Sys.plan ();
> val it = "apply2(fnValue List.at, tuple, tuple)" : string
(*) val hd : 'a list -> 'a
List.hd;
> val it = fn : 'a list -> 'a
List.hd [1,2,3];
> val it = 1 : int
List.hd [];
> uncaught exception Empty
> raised at: stdIn:1.1-1.11
Sys.plan ();
> val it = "apply(fnValue List.hd, argCode tuple)" : string
(*) val tl : 'a list -> 'a list
List.tl;
> val it = fn : 'a list -> 'a list
List.tl [1,2,3];
> val it = [2,3] : int list
List.tl [];
> uncaught exception Empty
> raised at: stdIn:1.1-1.11
Sys.plan ();
> val it = "apply(fnValue List.tl, argCode tuple)" : string
(*) val last : 'a list -> 'a
List.last;
> val it = fn : 'a list -> 'a
List.last [1,2,3];
> val it = 3 : int
List.last [];
> uncaught exception Empty
> raised at: stdIn:1.1-1.13
Sys.plan ();
> val it = "apply(fnValue List.last, argCode tuple)" : string
(*) val getItem : 'a list -> ('a * 'a list) option
List.getItem;
> val it = fn : 'a list -> ('a * 'a list) option
List.getItem [1,2,3];
> val it = SOME (1,[2,3]) : (int * int list) option
List.getItem [1];
> val it = SOME (1,[]) : (int * int list) option
Sys.plan ();
> val it = "apply(fnValue List.getItem, argCode tuple(constant(1)))" : string
(*) val nth : 'a list * int -> 'a
List.nth;
> val it = fn : 'a list * int -> 'a
List.nth ([1,2,3], 2);
> val it = 3 : int
List.nth ([1], 0);
> val it = 1 : int
List.nth ([1,2,3], 3);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.22
List.nth ([1,2,3], ~1);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.23
Sys.plan ();
> val it =
> "apply2(fnValue List.nth, tuple(constant(1), constant(2), constant(3)), constant(-1))"
> : string
(*) val take : 'a list * int -> 'a list
List.`take`;
> val it = fn : 'a list * int -> 'a list
List.`take` ([1,2,3], 0);
> val it = [] : int list
List.`take` ([1,2,3], 1);
> val it = [1] : int list
List.`take` ([1,2,3], 3);
> val it = [1,2,3] : int list
List.`take` ([1,2,3], 4);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.25
List.`take` ([1,2,3], ~1);
> uncaught exception Subscript [subscript out of bounds]
> raised at: stdIn:1.1-1.26
Sys.plan ();
> val it =
> "apply2(fnValue List.take, tuple(constant(1), constant(2), constant(3)), constant(-1))"
> : string
(*) val drop : 'a list * int -> 'a list
List.drop;
> val it = fn : 'a list * int -> 'a list
List.drop ([1,2,3], 0);
> val it = [1,2,3] : int list
List.drop ([1,2,3], 1);
> val it = [2,3] : int list
List.drop ([1,2,3], 3);
> val it = [] : int list
Sys.plan ();
> val it =
> "apply2(fnValue List.drop, tuple(constant(1), constant(2), constant(3)), constant(3))"
> : string
(*) val rev : 'a list -> 'a list
List.rev;
> val it = fn : 'a list -> 'a list
List.rev [1,2,3];
> val it = [3,2,1] : int list
List.rev [2,1];
> val it = [1,2] : int list
List.rev [1];
> val it = [1] : int list
List.rev [];
> val it = [] : 'a list
Sys.plan ();
> val it = "apply(fnValue List.rev, argCode tuple)" : string
(*) val concat : 'a list list -> 'a list
List.concat;
> val it = fn : 'a list list -> 'a list
List.concat [[1],[2,3],[4,5,6]];
> val it = [1,2,3,4,5,6] : int list
List.concat [[1],[],[4,5,6]];
> val it = [1,4,5,6] : int list
List.concat [[],[],[]];
> val it = [] : 'a list
List.concat [];
> val it = [] : 'a list
Sys.plan ();
> val it = "apply(fnValue List.concat, argCode tuple)" : string
(*) val revAppend : 'a list * 'a list -> 'a list
List.revAppend;
> val it = fn : 'a list * 'a list -> 'a list
List.revAppend ([1,2],[3,4,5]);
> val it = [2,1,3,4,5] : int list
List.revAppend ([1],[3,4,5]);
> val it = [1,3,4,5] : int list
List.revAppend ([],[3,4,5]);
> val it = [3,4,5] : int list
List.revAppend ([1,2],[]);
> val it = [2,1] : int list
List.revAppend ([],[]);
> val it = [] : 'a list
Sys.plan ();
> val it = "apply2(fnValue List.revAppend, tuple, tuple)" : string
(*) val app : ('a -> unit) -> 'a list -> unit
List.app;
> val it = fn : ('a -> unit) -> 'a list -> unit
List.app (fn x => ignore (x + 2)) [2,3,4];
> val it = () : unit
List.app (fn x => ignore (x + 2)) [];
> val it = () : unit
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.app, argCode match(x, apply(fnValue General.ignore, argCode apply2(fnValue +, get(name x), constant(2))))), argCode tuple)"
> : string
(*) val map : ('a -> 'b) -> 'a list -> 'b list
List.map;
> val it = fn : ('a -> 'b) -> 'a list -> 'b list
List.map (fn x => x + 1) [1,2,3];
> val it = [2,3,4] : int list
List.map (fn x => x + 1) [];
> val it = [] : int list
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.map, argCode match(x, apply2(fnValue +, get(name x), constant(1)))), argCode tuple)"
> : string
(*) map is alias for List.map
map;
> val it = fn : ('a -> 'b) -> 'a list -> 'b list
map (fn x => x) [];
> val it = [] : 'a list
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.map, argCode match(x, get(name x))), argCode tuple)"
> : string
(*) val mapPartial : ('a -> 'b option) -> 'a list -> 'b list
List.mapPartial;
> val it = fn : ('a -> 'b option) -> 'a list -> 'b list
List.mapPartial (fn x => if x mod 2 = 0 then NONE else SOME (x + 1)) [1,2,3,5,8];
> val it = [2,4,6] : int list
List.mapPartial (fn x => if x mod 2 = 0 then NONE else SOME (x + 1)) [];
> val it = [] : int list
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.mapPartial, argCode match(x, apply(fnCode match(true, constant([NONE]), _, apply(fnValue tyCon, argCode apply2(fnValue +, get(name x), constant(1)))), argCode apply2(fnValue =, apply2(fnValue mod, get(name x), constant(2)), constant(0))))), argCode tuple)"
> : string
(*) val find : ('a -> bool) -> 'a list -> 'a option
List.find;
> val it = fn : ('a -> bool) -> 'a list -> 'a option
List.find (fn x => x mod 7 = 0) [2,3,5,8,13,21,34];
> val it = SOME 21 : int option
List.find (fn x => x mod 11 = 0) [2,3,5,8,13,21,34];
> val it = NONE : int option
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.find, argCode match(x, apply2(fnValue =, apply2(fnValue mod, get(name x), constant(11)), constant(0)))), argCode tuple(constant(2), constant(3), constant(5), constant(8), constant(13), constant(21), constant(34)))"
> : string
(*) val filter : ('a -> bool) -> 'a list -> 'a list
List.filter;
> val it = fn : ('a -> bool) -> 'a list -> 'a list
List.filter (fn x => x mod 2 = 0) [0,1,2,3,4,5];
> val it = [0,2,4] : int list
List.filter (fn x => x mod 2 = 0) [1,3];
> val it = [] : int list
List.filter (fn x => x mod 2 = 0) [];
> val it = [] : int list
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.filter, argCode match(x, apply2(fnValue =, apply2(fnValue mod, get(name x), constant(2)), constant(0)))), argCode tuple)"
> : string
(*) val partition : ('a -> bool) -> 'a list -> 'a list * 'a list
List.partition;
> val it = fn : ('a -> bool) -> 'a list -> 'a list * 'a list
List.partition (fn x => x mod 2 = 0) [0,1,2,3,4,5];
> val it = ([0,2,4],[1,3,5]) : int list * int list
List.partition (fn x => x mod 2 = 0) [1];
> val it = ([],[1]) : int list * int list
List.partition (fn x => x mod 2 = 0) [];
> val it = ([],[]) : int list * int list
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.partition, argCode match(x, apply2(fnValue =, apply2(fnValue mod, get(name x), constant(2)), constant(0)))), argCode tuple)"
> : string
(*) val foldl : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
List.foldl;
> val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
List.foldl (fn (a, b) => a + b) 0 [1,2,3];
> val it = 6 : int
List.foldl (fn (a, b) => a + b) 0 [];
> val it = 0 : int
List.foldl (fn (a, b) => b) 0 [1,2,3];
> val it = 0 : int
List.foldl (fn (a, b) => a - b) 0 [1,2,3,4];
> val it = 2 : int
Sys.plan ();
> val it =
> "apply(fnCode apply(fnCode apply(fnValue List.foldl, argCode match(v0, apply(fnCode match((a, b), apply2(fnValue -, get(name a), get(name b))), argCode get(name v0)))), argCode constant(0)), argCode tuple(constant(1), constant(2), constant(3), constant(4)))"
> : string
(*) val foldr : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
List.foldr;
> val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
List.foldr (fn (a, b) => a + b) 0 [1,2,3];
> val it = 6 : int
List.foldr (fn (a, b) => a + b) 0 [];
> val it = 0 : int
List.foldr (fn (a, b) => b) 0 [1,2,3];
> val it = 0 : int
List.foldr (fn (a, b) => a - b) 0 [1,2,3,4];
> val it = ~2 : int
Sys.plan ();
> val it =
> "apply(fnCode apply(fnCode apply(fnValue List.foldr, argCode match(v0, apply(fnCode match((a, b), apply2(fnValue -, get(name a), get(name b))), argCode get(name v0)))), argCode constant(0)), argCode tuple(constant(1), constant(2), constant(3), constant(4)))"
> : string
(*) val exists : ('a -> bool) -> 'a list -> bool
List.exists;
> val it = fn : ('a -> bool) -> 'a list -> bool
List.exists (fn x => x mod 2 = 0) [1,3,5];
> val it = false : bool
List.exists (fn x => x mod 2 = 0) [2,4,6];
> val it = true : bool
List.exists (fn x => x mod 2 = 0) [1,2,3];
> val it = true : bool
List.exists (fn x => x mod 2 = 0) [];
> val it = false : bool
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.exists, argCode match(x, apply2(fnValue =, apply2(fnValue mod, get(name x), constant(2)), constant(0)))), argCode tuple)"
> : string
(*) val all : ('a -> bool) -> 'a list -> bool
List.all;
> val it = fn : ('a -> bool) -> 'a list -> bool
List.all (fn x => x mod 2 = 0) [1,3,5];
> val it = false : bool
List.all (fn x => x mod 2 = 0) [2,4,6];
> val it = true : bool
List.all (fn x => x mod 2 = 0) [1,2,3];
> val it = false : bool
List.all (fn x => x mod 2 = 0) [];
> val it = true : bool
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.all, argCode match(x, apply2(fnValue =, apply2(fnValue mod, get(name x), constant(2)), constant(0)))), argCode tuple)"
> : string
(*) val tabulate : int * (int -> 'a) -> 'a list
List.tabulate;
> val it = fn : int * (int -> 'a) -> 'a list
List.tabulate (5, let fun fact n = if n = 0 then 1 else n * fact (n - 1) in fact end);
> val it = [1,1,2,6,24] : int list
List.tabulate (1, let fun fact n = if n = 0 then 1 else n * fact (n - 1) in fact end);
> val it = [1] : int list
List.tabulate (0, let fun fact n = if n = 0 then 1 else n * fact (n - 1) in fact end);
> val it = [] : int list
List.tabulate (~1, let fun fact n = if n = 0 then 1 else n * fact (n - 1) in fact end);
> uncaught exception Size
> raised at: stdIn:1.1-1.87
Sys.plan ();
> val it =
> "apply(fnValue List.tabulate, argCode tuple(constant(-1), let1(matchCode match(fact, match(n, apply(fnCode match(true, constant(1), _, apply2(fnValue *, get(name n), apply(fnCode link, argCode apply2(fnValue -, get(name n), constant(1))))), argCode apply2(fnValue =, get(name n), constant(0))))), resultCode get(name fact))))"
> : string
(*) val collate : ('a * 'a -> order) -> 'a list * 'a list -> order
List.collate;
> val it = fn : ('a * 'a -> order) -> 'a list * 'a list -> order
List.collate (fn (x, y) => if x < y then LESS else if x = y then EQUAL else GREATER) ([1, 2,3], [1,3,4]);
> val it = LESS : order
List.collate (fn (x, y) => if x < y then LESS else if x = y then EQUAL else GREATER) ([1,2,3], [1,2,2]);
> val it = GREATER : order
List.collate (fn (x, y) => if x < y then LESS else if x = y then EQUAL else GREATER) ([1,2,3], [1,2]);
> val it = GREATER : order
List.collate (fn (x, y) => if x < y then LESS else if x = y then EQUAL else GREATER) ([1,2,3], [1,2,3,4]);
> val it = LESS : order
List.collate (fn (x, y) => if x < y then LESS else if x = y then EQUAL else GREATER) ([1,2,3], []);
> val it = GREATER : order
List.collate (fn (x, y) => if x < y then LESS else if x = y then EQUAL else GREATER) ([], []);
> val it = EQUAL : order
Sys.plan ();
> val it =
> "apply(fnCode apply(fnValue List.collate, argCode match(v0, apply(fnCode match((x, y), apply(fnCode match(true, constant([LESS]), _, apply(fnCode match(true, constant([EQUAL]), _, constant([GREATER])), argCode apply2(fnValue =, get(name x), get(name y)))), argCode apply2(fnValue <, get(name x), get(name y)))), argCode get(name v0)))), argCode tuple(tuple, tuple))"
> : string
(* Math -------------------------------------------------------- *)
(* The signature MATH specifies basic mathematical constants, the square root
function, and trigonometric, hyperbolic, exponential, and logarithmic
functions based on a real type. The functions defined here have roughly the
same semantics as their counterparts in ISO C's math.h.
In the functions below, unless specified otherwise, if any argument is a NaN,
the return value is a NaN. In a list of rules specifying the behavior of a
function in special cases, the first matching rule defines the semantics. *)
(* "acos x" returns the arc cosine of x. acos is the inverse of cos.
Its result is guaranteed to be in the closed interval [0, pi]. If
the magnitude of x exceeds 1.0, returns NaN. *)
Math.acos;