[m-dev.] deforestation missed opportunities

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Apr 9 00:13:45 AEST 2001


In the following example, I think deforestation ought to be able to
optimize the call to max_list([A,B,C].  It does unfold the call to max_list/1.
But it doesn't go the next step and unfold the call to max_list_aux/2.

	:- module max.
	:- interface.
	:- import_module int, list.

	:- func max_triple(int, int, int) = int.

	:- func max_list(list(int)) = int.

	:- implementation.
	:- import_module require.

	max_triple(A,B,C) = max_list([A,B,C]).

	max_list([]) = _ :- error("max of empty list").
	max_list([X|Xs]) = max_list_aux(X, Xs).

	:- func max_list_aux(int, list(int)) = int.
	max_list_aux(X, []) = X.
	max_list_aux(X, [Y|Ys]) = max_list_aux(int__max(X, Y), Ys).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list