[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell
Subject:    Re: `span' vs `partition'. Reply
From:       qrczak () knm ! org ! pl (Marcin 'Qrczak' Kowalczyk)
Date:       2000-05-31 7:14:18
Message-ID: slrn8j9eq9.q43.qrczak () qrnik ! knm ! org ! pl
[Download RAW message or body]

Wed, 31 May 2000 08:42:54 +0400 (MSD), S.D.Mechveliani <mechvel@math.botik.ru> pisze:

>              partition :: Char -> (a -> Bool) -> [a] -> ([a],[a])
>              groupBy   :: Char -> (a -> a -> Bool) -> [a] -> [[a]]
>              sort(By)  :: Char -> ...    

Please no! Using Char for a generic mode is almost as ugly as printf.
And makes incompatibilities between library versions hard to find.

If modified versions are really needed,

  * either make new functions (user always can pass functions as
    values if it must be chosen at runtime),

  * or uniformly parametrize them by what they use (example: there
    is no increasing / decreasing switch in sortBy because for that
    you just pass flipped comparison function),

  * or design better types (example: there is no signed and unsigned
    multiplication because signed and unsigned integer types are
    separate),

  * or split the function into two doing separate tasks,

  * or at most choose a better type for a mode (but not for partition
    and sortBy, they are too basic and elegant now).

Don't go too far at all. Standard libraries should not contain
every useful function, because too many features makes using more
common cases uglier, and learning what libraries contain longer.
Easy things should be easy, hard things should be possible.

A case for a mode arises when they are several independent options
which would multiply number of functions for each combination,
or a single option for many functions which would multiply each of
them, and they are chosen at runtime or have common wrappers. It is
mostly for system interface, e.g. opening a file. In system interface
inelegance of arbitrary design already has taken place.

A mode can be a string if choices are unbounded and thus not
interpreted by the library, but passed to something behind Haskell,
e.g. Socket.Service (a name from /etc/services).

-- 
 __("<    Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/              GCS/M d- s+:-- a23 C+++$ UL++>++++$ P+++ L++>++++$ E-
  ^^                  W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP+ t
QRCZAK                  5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic