[m-dev.] diff: random permutations

Peter Schachte schachte at cs.mu.OZ.AU
Tue Jan 4 15:33:45 AEDT 2000


On Tue, Jan 04, 2000 at 10:58:26AM +1100, Michael Day wrote:
> Would something like this be useful:
> 
> :- func '..'(T, T) = list(T) <= ordinal(T).
> :- mode '..'(in, in) = out is det.
> 
> '..'(Begin, End) = List :-
> 	(
> 		Begin < End
> 	->
> 		List = [Begin | (next(Begin) `..` End)]
> 	;
> 		Begin > End
> 	->
> 		List = [Begin | (prev(Begin) `..` End)]
> 	;
> 		List = [Begin]
> 	).	

I think it would be more useful to make '..'/2 an instance of a
sequence type class, rather than a function returning a list.  This
way you often wouldn't need to build the actual list.  (Alright,
deforestation can sometimes clean this up, but why require it for
efficiency?)

> (Sadly the long venerated "pred" and "succ" ordinal methods are unlikely
> to be of much use in Mercury, it just feels too weird to type "pred pred",
> syntactically correct or not :)

How about using +/2 and -/2 with an integer second argument as
generalized successor and predecessor methods?  They look reasonably
clear (at least to me), and you'd probably wind up inefficiently
defining them as repeated calls to successor/predecessor anyway.

-- 
Peter Schachte                     The hottest places in hell are reserved
mailto:schachte at cs.mu.OZ.AU        for those who, in time of great moral
http://www.cs.mu.oz.au/~schachte/  crisis, maintain their neutrality.
PGP: finger schachte at 128.250.37.3      -- Dante 
--------------------------------------------------------------------------
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