[m-dev.] diff: random permutations

Michael Day mcda at cat.cs.mu.OZ.AU
Tue Jan 4 10:58:26 AEDT 2000


> I think those procedures would probably be more generally useful
> building blocks.  And if we had both of those, there would be little
> advantage in adding their combination.
> 
> Note that Haskell has special syntax for (1),

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]
	).	

which assuming a suitably defined ordinal type class, would allow:

	Ints = 1 `..` 10,
	Chars = 'a' `..` 'z',
	
and so forth. Could substitute `to` for `..` if it was felt to be more
readable.

(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 :)

Michael

--------------------------------------------------------------------------
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