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
|
\DOC insert'
\TYPE {insert' : ('a -> 'a -> bool) -> 'a -> 'a list -> 'a list}
\SYNOPSIS
Insert element into list unless it contains an equivalent one already.
\DESCRIBE
If {r} is a binary relation, {x} an element and {l} a list, the call
{insert' r x l} will add {x} to the head of the list, unless the list already
contains an element {x'} with {r x x'}; if it does, the list is returned
unchanged. The function {insert} is the special case where {r} is equality.
\FAILURE
Fails only if the relation fails.
\EXAMPLE
{
# insert' (fun x y -> abs(x) = abs(y)) (-1) [1;2;3];;
val it : int list = [1; 2; 3]
# insert' (fun x y -> abs(x) = abs(y)) (-1) [2;3;4];;
val it : int list = [-1; 2; 3; 4]
}
\SEEALSO
insert, mem', subtract', union', unions'.
\ENDDOC
|