Bug#663180: Provides no zero value
David MENTRE <dmentre@linux-france.org> writes:
> Hello,
>
> 2012/3/10 Goswin von Brederlow <goswin-v-b@web.de>:
>>>> 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.
>
> Yes.
>
>> let () = Printf.printf "%s\n" (Sha1.to_hex (Sha1.string ""))
>> da39a3ee5e6b4b0d3255bfef95601890afd80709
>>
>> This would certainly work as an initializer but would not be obviously
>> invalid.
> [...]
>> This on the other hand is easy to spot in output or when stored in
>> files and unlikely to occur naturaly.
>
> I don't buy your argument (only a human can spot the 0000 value) but I
> understand your point of view.
>
> Another option would be to use Some h | None in your initialization
> code and convert it to an immutable value at the end of the
> initialization.
>
> Best regards,
> d.
An option type has the drawback that you have to extract it every time
you use it. That means more typing, less readable code and slower
code. That might seem minor but it does add up.
MfG
Goswin
Reply to: