[Haskell-cafe] Binary constants in Haskell
kolar at fit.vutbr.cz
Thu Oct 25 10:06:56 EDT 2007
// PLS, no flame
I think the question was not whether there's a way, how to handle the
problem of encryption of a binary number to anything suitable and, more
or less, readable by a human and transforming it to a binary form, but
whether there's such a literal or not and whether it is bad idea to have
something like 0b10111011.
From my point of view, the difference between 0b10111011 and
(bin[1,0,1,1,1,0,1,1]) is 22-10 that is 12 characters. Moreover,
allowing ADA features for all numeric literals we could have 0b1011_1011
;-) where the type would be Num a => a, of course.
So, i would expect only two answers: NO, it is ......., or YES, in
version 6.9.0 it is possible. ;-)
Ketil Malde wrote:
> Don Stewart <dons at galois.com> writes:
>>> Are there binary constants in Haskell, as
>>> we have, for instance, 0o232 for octal and
>>> 0xD29A for hexadecimal?
>> No, though it is an interesting idea.
> Presumably it is less common since octal and hexadecimal are more
> compact and almost as easy to interpret as bit patterns? Why would
> you want them?
> Prelude> let bin = foldl...
> Prelude> 0o232
> Prelude> bin [0,1,0, 0,1,1, 0,1,0]
> Prelude> 0xD29A
> Prelude> bin [1,1,0,1, 0,0,1,0, 1,0,0,1, 1,0,1,0]
Dusan Kolar tel: +420 54 114 1238
UIFS FIT VUT Brno fax: +420 54 114 1270
Bozetechova 2 e-mail: kolar at fit.vutbr.cz
Brno 612 66
More information about the Haskell-Cafe