argument order of functions in Data.Bits

Simon Marlow simonmar at microsoft.com
Thu Apr 7 05:52:06 EDT 2005


On 07 April 2005 07:54, Henning Thielemann wrote:

> The version of Data.Bits which is shipped with GHC-6.2 is marked as
> experimental. So changes in the API are still possible? :-]
> 
> My experiments suggest that the functions should have a different
> order of arguments. Many of the functions of this module alter some
> bits in a machine word, thus they can be considered as update
> functions and their type signature should end with a -> a. Then we
> could easily combine several operations this way
> 
>    shiftL 2 . clearBit 7 . setBit 4 . setBit 1
> 
> instead of
>    flip shiftL 2 . flip clearBit 7 . flip setBit 4 . flip setBit 1
> 
> or
>    (`shiftL` 2) . (`clearBit` 7) . (`setBit` 4) . (`setBit` 1)
> .
> 
> I don't see the benefit of urging the programmer to use infix notation
> instead of prefix notation here, e.g. (w `shift` 2) instead of 
> (shift 2 w).

On the whole I agree, but I'm inclined against changing this because it
would break so much code gratuitously.  I vote for just putting this
down to a small mistake in the original design, and leaving it.  If
there's overwhelming support for the change of course we'll make it, but
I doubt there will be.

Also the order of the arguments to shift matches C's shift operators
(although they are real infix operators, of course).

Cheers,
	Simon


More information about the Libraries mailing list