[m-dev.] For review: minor additions to list.m and string.m

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Sep 11 21:42:53 AEDT 2000


On 08-Sep-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > > > library/list.m:
> > > > 	Added func ++/2 as a synonym for list__append/2.
> > > > 	Added func '..'/1 to generate ascending/descending integer range
> > > > lists.
> > > 
> > > Firstly, s/1/2/.
> 
> Done.
> 
> > > I'm not sure this is the best way to do descending 
> > sequences. This means
> > > you can never generate an empty list.  Eg, I would find
> > > 
> > > 	1..0 = []
> > > 
> > > more natural than
> > > 
> > > 	1..0 = [1,0]
> > 
> > I agree.  Also the behaviour of `..' is inconsistent with Haskell,
> > for which `[1..0]' evaluates to `[]'.  In Haskell, you need to write
> > `[1,0..0]' to get `[1,0].
> 
> I, too, agree.  I just remember the last time someone suggested this
> they wanted the behaviour I implemented and there were no howls from
> the gallery.
> 
> How about this: `..`/2 is the inclusive ascending series
> 
> 	(N `..` M) = Seq
> 	  <=>  all [I] (index0(Seq, I, X) => (X = N + I, X =< M))

Sounds fine... but let's see the diff.

> and add
> 
> 	arith_series(N, M, D) = Seq
> 	  <=>  (      if D > 0 then
> 	                all [I] (index0(Seq, I, X) => (X = N + I * D, X =<
> M))
> 	         else if D < 0 then
> 	                all [I] (index0(Seq, I, X) => (X = N + I * D, X >=
> M))
>                else /* D = 0 */
>                       throw(a_wobbly)
> 	       )

I'm not convinced that arith_series is likely to be used often
enough to warrant inclusion in the standard library.

> Any takers for geom_series/3?  Or is that of too little use?  Mind you, it
> would be trivial to include.

I think geom_series/3 would be of too little use.
Something a bit like Haskell's `iterate' might be worthwhile, though.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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