On 02-Jun-2000, S.D.Mechveliani <[EMAIL PROTECTED]> wrote:
> Ketil Malde <[EMAIL PROTECTED]> writes
> 
> > I could accept "mode flags" if the algorithm is extremely similar,
> > e.g. passing a comparator function to a sort is a kind of mode flag
> > (think ordered/reversed) which I think is perfectly acceptable.
> > Having flags indicating algorithm to use (sort Merge (s:ss)) is IMHO
> > silly. 
> 
> 
> Not at all. Silly it to call differently the functions that compute
> the same map.
> Also silly is to have  quotRem & divMod   
> instead of             quotRem <mode>.

In addition to the criticisms that have already been leveled against
this approach, another drawback with it is that makes things less
extensible.

For example, with the current approach, if I want to define a new
sorting function, I just go ahead and do so, and apart from the
user of my new function having to import my module, my new sorting
function is completely first class, just like any sorting functions
that are provided by the Prelude or standard libraries.

But if we use mode arguments with some enumeration type, then there's
no easy way for me to add a new enumeration constant to the enum, or
to change the standard `sort' function so that it can call my sort
function.  So my new sort function ends up being in some sense a
second-class citizen in comparison to the various different sort
functions encapsulated as different modes of the standard `sort'
function.

For example, someone writing an algorithm that makes use of a sorting
function might well make the mistake of abstracting away which kind of
sort function is used by passing in a SortMode argument,

        foo :: SortMode -> ...
        foo mode ... = .... (sort mode) ...

rather than by passing in a sort function.  If they did that, then
I wouldn't be able to make `foo' use my own sort function.

(Note that using `Char' rather than an enumeration doesn't help with
this problem.)

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.

Reply via email to