212 val gen_subset: ('a * 'b -> bool) -> 'a list * 'b list -> bool |
212 val gen_subset: ('a * 'b -> bool) -> 'a list * 'b list -> bool |
213 val \ : ''a list * ''a -> ''a list |
213 val \ : ''a list * ''a -> ''a list |
214 val \\ : ''a list * ''a list -> ''a list |
214 val \\ : ''a list * ''a list -> ''a list |
215 val gen_rem: ('a * 'b -> bool) -> 'a list * 'b -> 'a list |
215 val gen_rem: ('a * 'b -> bool) -> 'a list * 'b -> 'a list |
216 val gen_rems: ('a * 'b -> bool) -> 'a list * 'b list -> 'a list |
216 val gen_rems: ('a * 'b -> bool) -> 'a list * 'b list -> 'a list |
217 val gen_distinct: ('a * 'a -> bool) -> 'a list -> 'a list |
|
218 val distinct: ''a list -> ''a list |
|
219 val findrep: ''a list -> ''a list |
217 val findrep: ''a list -> ''a list |
|
218 val distinct: ('a * 'a -> bool) -> 'a list -> 'a list |
220 val duplicates: ('a * 'a -> bool) -> 'a list -> 'a list |
219 val duplicates: ('a * 'a -> bool) -> 'a list -> 'a list |
221 val has_duplicates: ('a * 'a -> bool) -> 'a list -> bool |
220 val has_duplicates: ('a * 'a -> bool) -> 'a list -> bool |
222 |
221 |
223 (*lists as tables -- see also Pure/General/alist.ML*) |
222 (*lists as tables -- see also Pure/General/alist.ML*) |
224 val gen_merge_lists: ('a * 'a -> bool) -> 'a list -> 'a list -> 'a list |
223 val gen_merge_lists: ('a * 'a -> bool) -> 'a list -> 'a list -> 'a list |
1009 |
1008 |
1010 (*removing an element from a list -- possibly WITH duplicates*) |
1009 (*removing an element from a list -- possibly WITH duplicates*) |
1011 fun gen_rem eq (xs, y) = filter_out (fn x => eq (x, y)) xs; |
1010 fun gen_rem eq (xs, y) = filter_out (fn x => eq (x, y)) xs; |
1012 fun gen_rems eq (xs, ys) = filter_out (member eq ys) xs; |
1011 fun gen_rems eq (xs, ys) = filter_out (member eq ys) xs; |
1013 |
1012 |
|
1013 (*returns the tail beginning with the first repeated element, or []*) |
|
1014 fun findrep [] = [] |
|
1015 | findrep (x :: xs) = if x mem xs then x :: xs else findrep xs; |
|
1016 |
|
1017 |
1014 (*makes a list of the distinct members of the input; preserves order, takes |
1018 (*makes a list of the distinct members of the input; preserves order, takes |
1015 first of equal elements*) |
1019 first of equal elements*) |
1016 fun gen_distinct eq lst = |
1020 fun distinct eq lst = |
1017 let |
1021 let |
1018 fun dist (rev_seen, []) = rev rev_seen |
1022 fun dist (rev_seen, []) = rev rev_seen |
1019 | dist (rev_seen, x :: xs) = |
1023 | dist (rev_seen, x :: xs) = |
1020 if member eq rev_seen x then dist (rev_seen, xs) |
1024 if member eq rev_seen x then dist (rev_seen, xs) |
1021 else dist (x :: rev_seen, xs); |
1025 else dist (x :: rev_seen, xs); |
1022 in |
1026 in dist ([], lst) end; |
1023 dist ([], lst) |
|
1024 end; |
|
1025 |
|
1026 fun distinct l = gen_distinct (op =) l; |
|
1027 |
|
1028 (*returns the tail beginning with the first repeated element, or []*) |
|
1029 fun findrep [] = [] |
|
1030 | findrep (x :: xs) = if x mem xs then x :: xs else findrep xs; |
|
1031 |
|
1032 |
1027 |
1033 (*returns a list containing all repeated elements exactly once; preserves |
1028 (*returns a list containing all repeated elements exactly once; preserves |
1034 order, takes first of equal elements*) |
1029 order, takes first of equal elements*) |
1035 fun duplicates eq lst = |
1030 fun duplicates eq lst = |
1036 let |
1031 let |