[m-dev.] for review: function def's for single out det mode library predicates

Ralph Becket rwab1 at cam.sri.com
Thu Apr 29 01:26:17 AEST 1999


[And here is the version with the promised attachments...]
[Also, the library version this code was based on came from rotd-1999-04-16]

Estimated hours taken: 5

	I've added functions for the single output det predicates in a number
	of modules in the standard library.  Basically, for each

	:- pred f(in, ..., in, out) is det.

	I have added the declaration

	:- func f(in, ..., in) = out.

	and definition

	f(X1, ..., Xn) = Y :-
		f(X1, ..., Xn, Y).

library/array.m:
	As above, except array input modes are all array_ui or
	array_di as appropriate and array output modes are array_uo.

library/char.m:
	No special comments.

library/dir.m:
	No special comments.

library/int.m:
	Added forward versions of +/2, */2 and -/2 as plus/2, times/2
	and minus/2 respectively.  Also added func constants for
	max_int, min_int and bits_per_int.

library/integer.m:
	Replaced local functions for list head, tail and length with
	calls to equivalent functions now defined in list.m.

library/io.m:
	Added func for error_message/2.

library/list.m:
	No special comments, other than the addition of functions
	det_head/1 and det_tail/1 which abort on null lists.

library/map.m:
	No special comments.

library/set.m:
	No special comments, other than the addition of functions
	map/2, filter_map/2 and fold/3.

library/std_util.m:
	Added utility function to construct a pair object from its
	arguments and general purpose higher order functions for 
	partial functions and for function composition, exponentiation
	and exchanging the arguments of a binary function.

library/string.m:
	No special comments.

Hope this helps.  I've attached the diffs to this e-mail.  You may
wish to reorder the resulting code: most of this has been done by
appending extra interface and implementation sections to the files.

Ralph

-- 
Ralph Becket  |  rwab1 at cam.sri.com  |  http://www.cam.sri.com/people/becket.html
-------------- next part --------------
30a31,33
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
137a141
> 
180a185
> 
200a206
> 
211a218,220
> 	% XXX rwab1: I observe that the comparison procedure takes mode
> 	% in, in, out whereas historically this type of predicate is
> 
758a768,882
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
> :- interface.
> 
> :- func array__make_empty_array = array(T).
> :- mode array__make_empty_array = array_uo is det.
> 
> :- func array__init(int, T) = array(T).
> :- mode array__init(in, in) = array_uo is det.
> 
> :- func array__min(array(_T)) = int.
> :- mode array__min(array_ui) = out is det.
> 
> :- func array__max(array(_T)) = int.
> :- mode array__max(array_ui) = out is det.
> 
> :- func array__size(array(_T)) = int.
> :- mode array__size(array_ui) = out is det.
> 
> :- func array__lookup(array(T), int) = T.
> :- mode array__lookup(array_ui, in) = out is det.
> 
> 	% XXX rwab1: Is the above missing an in, in, in, out mode is det.
> :- func array__set(array(T), int, T) = array(T).
> :- mode array__set(array_di, in, in) = array_uo is det.
> 
> :- func array__slow_set(array(T), int, T) = array(T).
> :- mode array__slow_set(array_ui, in, in) = array_uo is det.
> 
> :- func array__copy(array(T)) = array(T).
> :- mode array__copy(array_ui) = array_uo is det.
> 
> :- func array__resize(array(T), int, T) = array(T).
> :- mode array__resize(array_di, in, in) = array_uo is det.
> 
> :- func array__shrink(array(T), int) = array(T).
> :- mode array__shrink(array_di, in) = array_uo is det.
> 
> :- func array__from_list(list(T)) = array(T).
> :- mode array__from_list(in) = array_uo is det.
> 
> :- func array__to_list(array(T)) = list(T).
> :- mode array__to_list(array_ui) = out is det.
> 
> :- func array__fetch_items(array(T), int, int) = list(T).
> :- mode array__fetch_items(array_ui, in, in) = out is det.
> 
> :- func array__bsearch(array(T), T, func(T,T) = comparison_result) = maybe(int).
> :- mode array__bsearch(array_ui, in, func(in,in) = out is det) = out is det.
> 
> :- func array__map(func(T1) = T2, array(T1)) = array(T2).
> :- mode array__map(func(in) = out is det, array_di) = array_uo is det.
> 
> :- func array_compare(array(T), array(T)) = comparison_result.
> :- mode array_compare(in, in) = out is det.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> array__make_empty_array = A :-
> 	array__make_empty_array(A).
> 
> array__init(N, X) = A :-
> 	array__init(N, X, A).
> 
> array__min(A) = N :-
> 	array__min(A, N).
> 
> array__max(A) = N :-
> 	array__max(A, N).
> 
> array__size(A) = N :-
> 	array__size(A, N).
> 
> array__lookup(A, N) = X :-
> 	array__lookup(A, N, X).
> 
> array__set(A1, N, X) = A2 :-
> 	array__set(A1, N, X, A2).
> 
> array__slow_set(A1, N, X) = A2 :-
> 	array__slow_set(A1, N, X, A2).
> 
> array__copy(A1) = A2 :-
> 	array__copy(A1, A2).
> 
> array__resize(A1, N, X) = A2 :-
> 	array__resize(A1, N, X, A2).
> 
> array__shrink(A1, N) = A2 :-
> 	array__shrink(A1, N, A2).
> 
> array__from_list(Xs) = A :-
> 	array__from_list(Xs, A).
> 
> array__to_list(A) = Xs :-
> 	array__to_list(A, Xs).
> 
> array__fetch_items(A, N1, N2) = Xs :-
> 	array__fetch_items(A, N1, N2, Xs).
> 
> array__bsearch(A, X, F) = MN :-
> 	P = ( pred(X1::in, X2::in, C::out) is det :- C = F(X1, X2) ),
> 	array__bsearch(A, X, P, MN).
> 
> array__map(F, A1) = A2 :-
> 	P = ( pred(X::in, Y::out) is det :- Y = F(X) ),
> 	array__map(P, A1, A2).
> 
> array_compare(A1, A2) = C :-
> 	array_compare(C, A1, A2).
> 
-------------- next part --------------
75a76,111
> %-----------------------------------------------------------------------------%
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
> :- interface.
> 
> :- func bool__or(bool, bool) = bool.
> 
> :- func bool__or_list(list(bool)) = bool.
> 
> :- func bool__and(bool, bool) = bool.
> 
> :- func bool__and_list(list(bool)) = bool.
> 
> :- func bool__not(bool) = bool.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> bool__or(X, Y) = Z :-
> 	bool__or(X, Y, Z).
> 
> bool__or_list(Xs) = Ys :-
> 	bool__or_list(Xs, Ys).
> 
> bool__and(X, Y) = Z :-
> 	bool__and(X, Y, Z).
> 
> bool__and_list(Xs) = Ys :-
> 	bool__and_list(Xs, Ys).
> 
> bool__not(X) = Y :-
> 	bool__not(X, Y).
> 
-------------- next part --------------
434c434
< 	
---
> 
435a436,478
> %-----------------------------------------------------------------------------%
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> %       Functional forms added.
> 
> :- interface.
> 
> :- func char__to_int(char) = int.
> 
> :- func char__max_char_value = int.
> 
> :- func char__min_char_value = int.
> 
> :- func char__to_upper(char) = char.
> 
> :- func char__to_lower(char) = char.
> 
> :- func char__det_int_to_digit(int) = char.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> char__to_int(C) = N :-
> 	char__to_int(C, N).
> 
> char__max_char_value = N :-
> 	char__max_char_value(N).
> 
> char__min_char_value = N :-
> 	char__min_char_value(N).
> 
> char__to_upper(C1) = C2 :-
> 	char__to_upper(C1, C2).
> 
> char__to_lower(C1) = C2 :-
> 	char__to_lower(C1, C2).
> 
> char__det_int_to_digit(N) = C :-
> 	char__det_int_to_digit(N, C).
> 
> 
> 
-------------- next part --------------
79a80,110
> %-----------------------------------------------------------------------------%
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> %       Functional forms added.
> 
> :- interface.
> 
> :- func dir__directory_separator = character.
> 
> :- func dir__this_directory = string.
> 
> :- func dir__basename(string) = string.
> 
> :- func dir__dirname(string) = string.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> dir__directory_separator = C :-
> 	dir__directory_separator(C).
> 
> dir__this_directory = S :-
> 	dir__this_directory(S).
> 
> dir__basename(S1) = S2 :-
> 	dir__basename(S1, S2).
> 
> dir__dirname(S1) = S2 :-
> 	dir__dirname(S1, S2).
> 
-------------- next part --------------
426a427,465
> %-----------------------------------------------------------------------------%
> %-----------------------------------------------------------------------------%
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> % 	Functional forms added.
> 
> :- interface.
> 
> :- func int__plus(int, int) = int.
> 
> :- func int__times(int, int) = int.
> 
> :- func int__minus(int, int) = int.
> 
> :- func int__max_int = int.
> 
> :- func int__min_int = int.
> 
> :- func int__bits_per_int = int.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> int__plus(X, Y) = X + Y.
> 
> int__times(X, Y) = X * Y.
> 
> int__minus(X, Y) = X - Y.
> 
> int__max_int = X :-
> 	int__max_int(X).
> 
> int__min_int = X :-
> 	int__min_int(X).
> 
> int__bits_per_int = X :-
> 	int__bits_per_int(X).
> 
-------------- next part --------------
627,630c627,630
< 		V0 = head(V),
< 		U0 = head(Ur),
< 		LengthUr = length(Ur),
< 		LengthV = length(V),
---
> 		V0 = list__det_head(V),
> 		U0 = list__det_head(Ur),
> 		LengthUr = list__length(Ur),
> 		LengthV = list__length(V),
633c633
< 			U1 = head(tail(Ur))
---
> 			U1 = list__det_head(list__det_tail(Ur))
640,642c640
< :- func length(list(T)) = int.
< length([]) = 0.
< length([_|Xs]) = 1 + length(Xs).
---
> 	% XXX rwab1 27/04/99: Versions of these functions now exist in list.m
644,658c642,660
< :- func head(list(T)) = T.
< head(HT) = H :-
< 	( HT = [Hd|_T] ->
< 		H = Hd
< 	;
< 		error("integer__head: []")
< 	).
< 		
< :- func tail(list(T)) = list(T).
< tail(HT) = T :-
< 	( HT = [_H|Tl] ->
< 		T = Tl
< 	;
< 		error("integer__tail: []")
< 	).
---
> % :- func length(list(T)) = int.
> % length([]) = 0.
> % length([_|Xs]) = 1 + length(Xs).
> % 
> % :- func head(list(T)) = T.
> % head(HT) = H :-
> % 	( HT = [Hd|_T] ->
> % 		H = Hd
> % 	;
> % 		error("integer__head: []")
> % 	).
> % 		
> % :- func tail(list(T)) = list(T).
> % tail(HT) = T :-
> % 	( HT = [_H|Tl] ->
> % 		T = Tl
> % 	;
> % 		error("integer__tail: []")
> % 	).
-------------- next part --------------
3397a3398,3415
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> %	Functional forms added.
> 
> :- interface.
> 
> :- func io__error_message(io__error) = string.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> io__error_message(Error) = Msg :-
> 	io__error_message(Error, Msg).
> 
-------------- next part --------------
1129a1130,1299
> %-----------------------------------------------------------------------------%
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> % 	Functional forms added.
> 
> :- interface.
> 
> :- func list__det_head(list(T)) = T.
> 
> :- func list__det_tail(list(T)) = list(T).
> 
> :- func list__append(list(T), list(T)) = list(T).
> 
> :- func list__merge(list(T), list(T)) = list(T).
> 
> :- func list__merge_and_remove_dups(list(T), list(T)) = list(T).
> 
> :- func list__remove_adjacent_dups(list(T)) = list(T).
> 
> :- func list__remove_dups(list(T)) = list(T).
> 
> :- func list__length(list(T)) = int.
> 
> :- func list__take_upto(int, list(T)) = list(T).
> 
> :- func list__delete_all(list(T), T) = list(T).
> 
> :- func list__delete_elems(list(T), list(T)) = list(T).
> 
> :- func list__replace_all(list(T), T, T) = list(T).
> 
> :- func list__replace_nth_det(list(T), int, T) = list(T).
> 
> :- func list__sort_and_remove_dups(list(T)) = list(T).
> 
> :- func list__sort(list(T)) = list(T).
> 
> :- func list__reverse(list(T)) = list(T).
> 
> :- func list__index0_det(list(T), int) = T.
> 
> :- func list__index1_det(list(T), int) = T.
> 
> :- func list__zip(list(T), list(T)) = list(T).
> 
> :- func list__duplicate(int, T) = list(T).
> 
> :- func list__condense(list(list(T))) = list(T).
> 
> :- func list__chunk(list(T), int) = list(list(T)).
> 
> :- func list__map(func(X) = Y, list(X)) = list(Y).
> 
> :- func list__foldl(func(X, Y) = Y, list(X), Y) = Y.
> 
> :- func list__foldr(func(X, Y) = Y, list(X), Y) = Y.
> 
> :- func list__filter(pred(X), list(X)) = list(X).
> :- mode list__filter(pred(in) is semidet, in) = out is det.
> 
> :- func list__filter_map(func(X) = Y, list(X)) = list(Y).
> :- mode list__filter_map(func(in) = out is semidet, in) = out is det.
> 
> :- func list__sort(func(X, X) = comparison_result, list(X)) = list(X).
> 
> :- func list__merge(func(X, X) = comparison_result, list(X), list(X)) = list(X).
> 
> :- func list__merge_and_remove_dups(func(X, X) = comparison_result, list(X), list(X)) = list(X).
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> list__det_head([]) = _ :- error("list__det_head/1: empty list as argument").
> list__det_head([X | _]) = X.
> 
> list__det_tail([]) = _ :- error("list__det_tail/1: empty list as argument").
> list__det_tail([_ | Xs]) = Xs.
> 
> list__append(Xs, Ys) = Zs :-
> 	list__append(Xs, Ys, Zs).
> 
> list__merge(Xs, Ys) = Zs :-
> 	list__merge(Xs, Ys, Zs).
> 
> list__merge_and_remove_dups(Xs, Ys) = Zs :-
> 	list__merge_and_remove_dups(Xs, Ys, Zs).
> 
> list__remove_adjacent_dups(Xs) = Ys :-
> 	list__remove_adjacent_dups(Xs, Ys).
> 
> list__remove_dups(Xs) = Ys :-
> 	list__remove_dups(Xs, Ys).
> 
> list__length(Xs) = N :-
> 	list__length(Xs, N).
> 
> list__take_upto(N, Xs) = Ys :-
> 	list__take_upto(N, Xs, Ys).
> 
> list__delete_all(Xs, A) = Ys :-
> 	list__delete_all(Xs, A, Ys).
> 
> list__delete_elems(Xs, Ys) = Zs :-
> 	list__delete_elems(Xs, Ys, Zs).
> 
> list__replace_all(Xs, A, B) = Ys :-
> 	list__replace_all(Xs, A, B, Ys).
> 
> list__replace_nth_det(Xs, N, A) = Ys :-
> 	list__replace_nth_det(Xs, N, A, Ys).
> 
> list__sort_and_remove_dups(Xs) = Ys :-
> 	list__sort_and_remove_dups(Xs, Ys).
> 
> list__sort(Xs) = Ys :-
> 	list__sort(Xs, Ys).
> 
> list__reverse(Xs) = Ys :-
> 	list__reverse(Xs, Ys).
> 
> list__index0_det(Xs, N) = A :-
> 	list__index0_det(Xs, N, A).
> 
> list__index1_det(Xs, N) = A :-
> 	list__index1_det(Xs, N, A).
> 
> list__zip(Xs, Ys) = Zs :-
> 	list__zip(Xs, Ys, Zs).
> 
> list__duplicate(N, A) = Xs :-
> 	list__duplicate(N, A, Xs).
> 
> list__condense(Xss) = Ys :-
> 	list__condense(Xss, Ys).
> 
> list__chunk(Xs, N) = Ys :-
> 	list__chunk(Xs, N, Ys).
> 
> list__map(F, Xs) = Ys :-
> 	P = ( pred(X::in, Y::out) is det :- Y = F(X) ),
> 	list__map(P, Xs, Ys).
> 
> list__foldl(F, Xs, A) = B :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	list__foldl(P, Xs, A, B).
> 
> list__foldr(F, Xs, A) = B :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	list__foldr(P, Xs, A, B).
> 
> list__filter(P, Xs) = Ys :-
> 	list__filter(P, Xs, Ys).
> 
> list__filter_map(F, Xs) = Ys :-
> 	P = ( pred(X::in, Y::out) is semidet :- Y = F(X) ),
> 	list__filter_map(P, Xs, Ys).
> 
> list__sort(F, Xs) = Ys :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	list__sort(P, Xs, Ys).
> 
> list__merge(F, Xs, Ys) = Zs :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	list__merge(P, Xs, Ys, Zs).
> 
> list__merge_and_remove_dups(F, Xs, Ys) = Zs :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	list__merge_and_remove_dups(P, Xs, Ys, Zs).
> 
-------------- next part --------------
605a606,764
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> % 	Functional forms added.
> 
> :- interface.
> 
> :- func map__lookup(map(K,V), K) = V.
> 
> :- func map__det_insert(map(K,V), K, V) = map(K,V).
> 
> :- func map__det_insert_from_corresponding_lists(map(K,V), list(K), list(V)) =
> 		map(K,V).
> 
> :- func map__det_insert_from_assoc_list(map(K,V), assoc_list(K, V)) = map(K,V).
> 
> :- func map__det_update(map(K,V), K, V) = map(K,V).
> 
> :- func map__set(map(K,V), K, V) = map(K,V).
> 
> :- func map__keys(map(K, _V)) = list(K).
> 
> :- func map__sorted_keys(map(K, _V)) = list(K).
> 
> :- func map__values(map(_K, V)) = list(V).
> 
> :- func map__to_assoc_list(map(K,V)) = assoc_list(K,V).
> 
> :- func map__to_sorted_assoc_list(map(K,V)) = assoc_list(K,V).
> 
> :- func map__from_assoc_list(assoc_list(K,V)) = map(K,V).
> 
> :- func map__from_sorted_assoc_list(assoc_list(K,V)) = map(K,V).
> 
> :- func map__delete(map(K,V), K) = map(K,V).
> 
> :- func map__delete_list(map(K,V), list(K)) = map(K,V).
> 
> :- func map__count(map(K, V)) = int.
> 
> :- func map__from_corresponding_lists(list(K), list(V)) = map(K, V).
> 
> :- func map__merge(map(K, V), map(K, V)) = map(K, V).
> 
> :- func map__overlay(map(K,V), map(K,V)) = map(K,V).
> 
> :- func map__select(map(K,V), set(K)) = map(K,V).
> 
> :- func map__apply_to_list(list(K), map(K, V)) = list(V).
> 
> :- func map__optimize(map(K, V)) = map(K, V).
> 
> :- func map__foldl(func(K, V, T) = T, map(K, V), T) = T.
> 
> :- func map__map_values(func(K, V) = W, map(K, V)) = map(K, W).
> 
> :- func map__intersect(func(V, V) = V, map(K, V), map(K, V)) = map(K, V).
> 
> :- func map__det_intersect(func(V, V) = V, map(K, V), map(K, V)) = map(K, V).
> :- mode map__det_intersect(func(in, in) = out is semidet, in, in) = out is det.
> 
> :- func map__union(func(V, V) = V, map(K, V), map(K, V)) = map(K, V).
> 
> :- func map__det_union(func(V, V) = V, map(K, V), map(K, V)) = map(K, V).
> :- mode map__det_union(func(in, in) = out is semidet, in, in) = out is det.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> map__lookup(M, K) = V :-
> 	map__lookup(M, K, V).
> 
> map__det_insert(M1, K, V) = M2 :-
> 	map__det_insert(M1, K, V, M2).
> 
> map__det_insert_from_corresponding_lists(M1, Ks, Vs) = M2 :-
> 	map__det_insert_from_corresponding_lists(M1, Ks, Vs, M2).
> 
> map__det_insert_from_assoc_list(M1, AL) = M2 :-
> 	map__det_insert_from_assoc_list(M1, AL, M2).
> 
> map__det_update(M1, K, V) = M2 :-
> 	map__det_update(M1, K, V, M2).
> 
> map__set(M1, K, V) = M2 :-
> 	map__set(M1, K, V, M2).
> 
> map__keys(M) = Ks :-
> 	map__keys(M, Ks).
> 
> map__sorted_keys(M) = Ks :-
> 	map__sorted_keys(M, Ks).
> 
> map__values(M) = Vs :-
> 	map__values(M, Vs).
> 
> map__to_assoc_list(M) = AL :-
> 	map__to_assoc_list(M, AL).
> 
> map__to_sorted_assoc_list(M) = AL :-
> 	map__to_sorted_assoc_list(M, AL).
> 
> map__from_assoc_list(AL) = M :-
> 	map__from_assoc_list(AL, M).
> 
> map__from_sorted_assoc_list(AL) = M :-
> 	map__from_sorted_assoc_list(AL, M).
> 
> map__delete(M1, K) = M2 :-
> 	map__delete(M1, K, M2).
> 
> map__delete_list(M1, Ks) = M2 :-
> 	map__delete_list(M1, Ks, M2).
> 
> map__count(M) = N :-
> 	map__count(M, N).
> 
> map__from_corresponding_lists(Ks, Vs) = M :-
> 	map__from_corresponding_lists(Ks, Vs, M).
> 
> map__merge(M1, M2) = M3 :-
> 	map__merge(M1, M2, M3).
> 
> map__overlay(M1, M2) = M3 :-
> 	map__overlay(M1, M2, M3).
> 
> map__select(M1, S) = M2 :-
> 	map__select(M1, S, M2).
> 
> map__apply_to_list(Ks, M) = Vs :-
> 	map__apply_to_list(Ks, M, Vs).
> 
> map__optimize(M1) = M2 :-
> 	map__optimize(M1, M2).
> 
> map__foldl(F, M, A) = B :-
> 	P = ( pred(W::in, X::in, Y::in, Z::out) is det :- Z = F(W, X, Y) ),
> 	map__foldl(P, M, A, B).
> 
> map__map_values(F, M1) = M2 :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	map__map_values(P, M1, M2).
> 
> map__intersect(F, M1, M2) = M3 :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	map__intersect(P, M1, M2, M3).
> 
> map__det_intersect(PF, M1, M2) = M3 :-
> 	P = ( pred(X::in, Y::in, Z::out) is semidet :- Z = PF(X, Y) ),
> 	map__det_intersect(P, M1, M2, M3).
> 
> map__union(F, M1, M2) = M3 :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	map__union(P, M1, M2, M3).
> 
> map__det_union(F, M1, M2) = M3 :-
> 	P = ( pred(X::in, Y::in, Z::out) is semidet :- Z = F(X, Y) ),
> 	map__det_union(P, M1, M2, M3).
> 
-------------- next part --------------
14a15,17
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
28a32,33
> :- func set__list_to_set(list(T)) = set(T).
> 
35a41,42
> :- func set__sorted_list_to_set(list(T)) = set(T).
> 
42a50,51
> :- func set__to_sorted_list(set(T)) = list(T).
> 
47a57,58
> :- func set__init = set(T).
> 
54a66,67
> :- func set__make_singleton_set(T) = set(T).
> 
93a107,110
> 	% XXX rwab1: I think we should reverse the args. here for
> 	% higher order programming.
> :- func set__insert(set(T), T) = set(T).
> 
99a117,120
> 	% XXX rwab1: I think we should reverse the args. here for
> 	% higher order programming.
> :- func set__insert_list(set(T), list(T)) = set(T).
> 
108a130,133
> 	% XXX rwab1: I think we should reverse the args. here for
> 	% higher order programming.
> :- func set__delete(set(T), T) = set(T).
> 
115a141,144
> 	% XXX rwab1: I think we should reverse the args. here for
> 	% higher order programming.
> :- func set__delete_list(set(T), list(T)) = set(T).
> 
152a182,183
> :- func set__union(set(T), set(T)) = set(T).
> 
158a190,191
> :- func set__power_union(set(set(T))) = set(T).
> 
171a205,206
> :- func set__intersect(set(T), set(T)) = set(T).
> 
177a213,214
> :- func set__power_intersect(set(set(T))) = set(T).
> 
184a222,223
> :- func set__difference(set(T), set(T)) = set(T).
> 
189a229,239
> :- func set__count(set(T)) = int.
> 
> 	% Support for higher order set processing.
> 
> :- func set__map(func(T1) = T2, set(T1)) = set(T2).
> 
> :- func set__filter_map(func(T1) = T2, set(T1)) = set(T2).
> :- mode set__filter_map(func(in) = out is semidet, in) = out is det.
> 
> :- func set__fold(func(T1, T2) = T2, set(T1), T2) = T2.
> 
271a322,378
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
> set__list_to_set(Xs) = S :-
> 	set__list_to_set(Xs, S).
> 
> set__sorted_list_to_set(Xs) = S :-
> 	set__sorted_list_to_set(Xs, S).
> 
> set__to_sorted_list(S) = Xs :-
> 	set__to_sorted_list(S, Xs).
> 
> set__init = S :-
> 	set__init(S).
> 
> set__make_singleton_set(T) = S :-
> 	set__singleton_set(S, T).
> 
> set__insert(S1, T) = S2 :-
> 	set__insert(S1, T, S2).
> 
> set__insert_list(S1, Xs) = S2 :-
> 	set__insert_list(S1, Xs, S2).
> 
> set__delete(S1, T) = S2 :-
> 	set__delete(S1, T, S2).
> 
> set__delete_list(S1, Xs) = S2 :-
> 	set__delete_list(S1, Xs, S2).
> 
> set__union(S1, S2) = S3 :-
> 	set__union(S1, S2, S3).
> 
> set__power_union(SS) = S :-
> 	set__power_union(SS, S).
> 
> set__intersect(S1, S2) = S3 :-
> 	set__intersect(S1, S2, S3).
> 
> set__power_intersect(SS) = S :-
> 	set__power_intersect(SS, S).
> 
> set__difference(S1, S2) = S3 :-
> 	set__difference(S1, S2, S3).
> 
> set__count(S) = N :-
> 	set__count(S, N).
> 
> set__map(F, S1) = S2 :-
> 	S2 = set__list_to_set(list__map(F, set__to_sorted_list(S1))).
> 
> set__filter_map(PF, S1) = S2 :-
> 	S2 = set__list_to_set(list__filter_map(PF, set__to_sorted_list(S1))).
> 
> set__fold(F, S, A) = B :-
> 	B = list__foldl(F, set__to_sorted_list(S), A).
> 
-------------- next part --------------
13a14,16
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
2765a2769,2815
> %-----------------------------------------------------------------------------%
> % Ralph Becket <rwab1 at cam.sri.com> 24/04/99
> %	Function forms added.
> 
> :- interface.
> 
> :- func pair(T1, T2) = pair(T1, T2).
> 
> :- func maybe_func(func(T1) = T2, T1) = maybe(T2).
> :- mode maybe_func(func(in) = out is semidet, in) = out is det.
> 
> 	% General purpose higher-order programming constructs.
> 
> 	% o(F, G, X) = F(G(X))
> 	%
> 	% Function composition.
> 	% XXX It would be nice to have infix `o' or somesuch for this.
> :- func o(func(T2) = T3, func(T1) = T2, T1) = T3.
> 
> 	% converse(F, X, Y) = F(Y, X)
> :- func converse(func(T1, T2) = T3, T2, T1) = T3.
> 
> 	% pow(F, N, X) = F^N(X)
> 	%
> 	% Function exponentiation.
> :- func pow(func(T) = T, int, T) = T.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> pair(X, Y) =
> 	X-Y.
> 
> maybe_func(PF, X) =
> 	( if Y = PF(X) then yes(Y) else no ).
> 
> o(F, G, X) =
> 	F(G(X)).
> 
> converse(F, X, Y) =
> 	F(Y, X).
> 
> pow(F, N, X) =
> 	( if N = 0 then X else pow(F, N - 1, F(X)) ).
> 
-------------- next part --------------
1969,1970d1968
< :- end_module string.
< 
1972a1971,2118
> % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
> %       Functional forms added.
> 
> :- interface.
> 
> :- func string__append(string, string) = string.
> 
> :- func string__char_to_string(char) = string.
> 
> :- func string__int_to_string(int) = string.
> 
> :- func string__int_to_base_string(int, int) = string.
> 
> :- func string__float_to_string(float) = string.
> 
> :- func string__replace_all(string, string, string) = string.
> 
> :- func string__to_lower(string) = string.
> 
> :- func string__to_upper(string) = string.
> 
> :- func string__capitalize_first(string) = string.
> 
> :- func string__uncapitalize_first(string) = string.
> 
> :- func string__to_char_list(string) = list(char).
> 
> :- func string__from_char_list(list(char)) = string.
> 
> :- func string__from_rev_char_list(list(char)) = string.
> 
> :- func string__pad_left(string, char, int) = string.
> 
> :- func string__pad_right(string, char, int) = string.
> 
> :- func string__duplicate_char(char, int) = string.
> 
> :- func string__index_det(string, int) = char.
> 
> :- func string__unsafe_index(string, int) = char.
> 
> :- func string__foldl(func(char, T) = T, string, T) = T.
> 
> :- func string__left(string, int) = string.
> 
> :- func string__right(string, int) = string.
> 
> :- func string__substring(string, int, int) = string.
> 
> :- func string__unsafe_substring(string, int, int) = string.
> 
> :- func string__append_list(list(string)) = string.
> 
> :- func string__hash(string) = int.
> 
> :- func string__format(string, list(string__poly_type)) = string.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- implementation.
> 
> string__append(S1, S2) = S3 :-
> 	string__append(S1, S2, S3).
> 
> string__char_to_string(C) = S1 :-
> 	string__char_to_string(C, S1).
> 
> string__int_to_string(N) = S1 :-
> 	string__int_to_string(N, S1).
> 
> string__int_to_base_string(N1, N2) = S2 :-
> 	string__int_to_base_string(N1, N2, S2).
> 
> string__float_to_string(R) = S2 :-
> 	string__float_to_string(R, S2).
> 
> string__replace_all(S1, S2, S3) = S4 :-
> 	string__replace_all(S1, S2, S3, S4).
> 
> string__to_lower(S1) = S2 :-
> 	string__to_lower(S1, S2).
> 
> string__to_upper(S1) = S2 :-
> 	string__to_upper(S1, S2).
> 
> string__capitalize_first(S1) = S2 :-
> 	string__capitalize_first(S1, S2).
> 
> string__uncapitalize_first(S1) = S2 :-
> 	string__uncapitalize_first(S1, S2).
> 
> string__to_char_list(S) = Cs :-
> 	string__to_char_list(S, Cs).
> 
> string__from_char_list(Cs) = S :-
> 	string__from_char_list(Cs, S).
> 
> string__from_rev_char_list(Cs) = S :-
> 	string__from_rev_char_list(Cs, S).
> 
> string__pad_left(S1, C, N) = S2 :-
> 	string__pad_left(S1, C, N, S2).
> 
> string__pad_right(S1, C, N) = S2 :-
> 	string__pad_right(S1, C, N, S2).
> 
> string__duplicate_char(C, N) = S :-
> 	string__duplicate_char(C, N, S).
> 
> string__index_det(S, N) = C :-
> 	string__index_det(S, N, C).
> 
> string__unsafe_index(S, N) = C :-
> 	string__unsafe_index(S, N, C).
> 
> string__foldl(F, S, A) = B :-
> 	P = ( pred(X::in, Y::in, Z::out) is det :- Z = F(X, Y) ),
> 	string__foldl(P, S, A, B).
> 
> string__left(S1, N) = S2 :-
> 	string__left(S1, N, S2).
> 
> string__right(S1, N) = S2 :-
> 	string__right(S1, N, S2).
> 
> string__substring(S1, N1, N2) = S2 :-
> 	string__substring(S1, N1, N2, S2).
> 
> string__unsafe_substring(S1, N1, N2) = S2 :-
> 	string__unsafe_substring(S1, N1, N2, S2).
> 
> string__append_list(S1s) = S2 :-
> 	string__append_list(S1s, S2).
> 
> string__hash(S) = N :-
> 	string__hash(S, N).
> 
> string__format(S1, PT) = S2 :-
> 	string__format(S1, PT, S2).
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %
> 
> :- end_module string.
> 
> % ---------------------------------------------------------------------------- %
> % ---------------------------------------------------------------------------- %


More information about the developers mailing list