-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sig
102 lines (72 loc) · 3.4 KB
/
utils.sig
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
sig utils.
% I/O PREDICATES
% [nl] prints a newline character to standard output.
type nl o.
% [println +S] prints string [S] to standard output followed by a
% newline character.
type println string -> o.
% [write +A] prints an arbitrary value to standard output.
type write A -> o.
% [writeln +A] prints an arbitrary value to standard output, appending
% a newline character.
type writeln A -> o.
% LIST PREDICATES
% [length +L N] returns length of list [L] in N.
type length list A -> int -> o.
% [nth +L +N X] returns [N]th element of list [L] in [X] if it exists.
type nth list A -> int -> A -> o.
% [rev L1 L2] list [L1] is the reverse of list [L2].
type rev list A -> list A -> o.
% [append L1 L2 L3] list [L1] appended to list [L2] yields list [L3].
type append list A -> list A -> list A -> o.
% [flatten L R] flattens list of lists [L] to list [R].
type flatten list (list A) -> list A -> o.
% [rev_append L1 L2 L3] list [L1] reversed and appended to list [L2]
% yields list [L3].
type rev_append list A -> list A -> list A -> o.
% [mapP +P +L R] maps predicate [P] over list [L] returning result in [R].
type mapP (A -> B -> o) -> list A -> list B -> o.
% [rev_mapP +P +L R] maps predicate [P] over list [L] returning the
% reversed result in [R].
type rev_mapP (A -> B -> o) -> list A -> list B -> o.
% [fold_leftP +P A +L R] accumulates a value [R] left-associatively
% walking over list [L], starting with accumulator [A] and using predicate
% [P].
type fold_leftP (A -> B -> A -> o) -> A -> list B -> A -> o.
% [fold_rightP +P +L A R] accumulates a value [R] right-associatively
% walking over list [L], starting with accumulator [A] and using predicate
% [P].
type fold_rightP (B -> A -> B -> o) -> list A -> B -> B -> o.
% [forall +P +L] checks whether predicate [P] holds for all elements of
% list [L]. Can also be used to iterate over a list.
type forall (A -> o) -> list A -> o.
% [exists +P +L] checks whether predicate [P] holds for at least one
% element of list [L].
type exists (A -> o) -> list A -> o.
% [mem +X +L] checks whether [X] is contained in list [L]. Does not
% backtrack to further solutions! (efficient).
type mem A -> list A -> o.
% [member X +L] checks whether [X] is contained in list [L]. Backtracks
% for further solutions!
type member A -> list A -> o.
% [find +P +L X] tries to find an element [X] of list [L] that satisfies
% predicate [P]. Backtracks for more solutions.
type find (A -> o) -> list A -> A -> o.
% [filter +P +L R] filters out all elements (in order) of list [L]
% that satisfy predicate [P], returning the result in [R].
type filter (A -> o) -> list A -> list A -> o.
% [partition +P +L Yes No] partitions list [L] into lists of elements
% that satisfy predicate [P] ([Yes]) or don't ([No]).
type partition (A -> o) -> list A -> list A -> list A -> o.
% [qsort +P +L R] sorts list [L] using order relation [P], returning
% the result in [R]. Uses the quicksort algorithm.
type qsort (A -> A -> o) -> list A -> list A -> o.
% GENERAL PREDICATES ON TERMS
% [contains T ST] checks whether some term [T] contains a subterm [ST].
type contains A -> B -> o.
% [elim_sub_term T ST F] eliminates subterm [ST] from term [T] using
% substitution function [F].
type elim_sub_term A -> B -> (B -> A) -> o.
% [elim_sub_patterns T PGen F] eliminates subpatterns generated by
% pattern generator [PGen] from term [T] using substitution function [F].
type elim_sub_patterns A -> (B -> o) -> (B -> A) -> o.