[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#663180: Provides no zero value



Eric Cooper <ecc@cmu.edu> writes:

> On Sat, Mar 10, 2012 at 02:00:58PM +0100, Goswin von Brederlow wrote:
>> David MENTRE <dmentre@linux-france.org> writes:
>> 
>> > Hello,
>> >
>> > 2012/3/9 Goswin von Brederlow <goswin-v-b@web.de>:
>> >> I found myself in a situation where I needed to fill in a dummy Sha1.t
>> >> into a record to initialize an array. I didn't want to use an Sha1.t
>> >> option because the value is only every invalid during initialization
>> >> and an option type would mean extracting from "Some x" at every other
>> >> place.
>> >>
>> >> The attached patch adds a Sha*.zero value that can be used for this
>> >> purpose.
>> >
>> > Why don't you define this Sha1.zero value in your code and use it
>> > there? This patch seems to me very specific to your code and of
>> > dubious use in a library.
>> >
>> > Best regards,
>> > david
>> 
>> I can't because the Sha1.t is abstract.
>
> I think what David means is that  you can just define
>     let my_initializer = Sha1.string ""
> somewhere at the beginning of your code.

let () = Printf.printf "%s\n" (Sha1.to_hex (Sha1.string ""))
da39a3ee5e6b4b0d3255bfef95601890afd80709

This would certainly work as an initializer but would not be obviously
invalid. There certainly will be instances where people will hash "" and
then they look the same and would test true with structural equality.

let () = Printf.printf "%s\n" (Sha1.to_hex Sha1.zero)
0000000000000000000000000000000000000000

This on the other hand is easy to spot in output or when stored in
files and unlikely to occur naturaly.

MfG
        Goswin



Reply to: