[Haskell-cafe] Binary constants in Haskell

Iavor Diatchki iavor.diatchki at gmail.com
Thu Oct 25 11:14:08 EDT 2007


Hi,

We have no binary literals in Haskell and there are situations when it
would have been useful to have this feature (e.g., if the spec of
something that you are working with is already provided using this
notation).

While it may be useful to have overloaded binary literals in the usual
Haskell style, during my PhD work I found that it is also useful
(perhaps even more so) to add non-overloaded binary literals where the
number of digits in the literal determines its type.  The notation
that I used was B00010011 to be a literal of type Word8.  I chose this
notation over one like 0b00010011 because I think that the leading
zero is confusing (the literal usually has plenty of 0s already!).
Also, I like it that my notation suggests that the literals are the
constructors of the corresponding word type.

I think that binary literals are more useful when you work with fairly
short bit sequences, mixing and matching to make longer ones.
Unfortunately, in current Haskell we don't have a family of word types
but instead, a few predefined ones, the shortest of which is Word8, so
perhaps this notation is not so useful.   (I have encoded families of
word types in Haskell, but I think that having language support for
such things as in my work on bitdata, in bluespec, or cryptol is much
nicer).

Hope this helps!
-Iavor

On 10/25/07, Ketil Malde <ketil+haskell at ii.uib.no> wrote:
> Dusan Kolar <kolar at fit.vutbr.cz> writes:
>
> >  // PLS, no flame
>
> I apologize if my post came across as such, that was certainly not the
> intent.
>
> > I think the question was [..] whether there's such a literal or not
> > and whether it is bad idea to have something like 0b10111011.
>
> I agree.
>
> >  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.
>
> And from my point of view, 0xEE or 0x273 are equally readable, and
> even more succinct.  If you are into bit-twiddling, that is.  For
> user-friendly bitfields you should obviously provide a higher level
> interface.
>
> >  So, i would expect only two answers: NO, it is .......,  or YES, in
> > version 6.9.0 it is possible. ;-)
>
> As far as I know, there are no such plans.  Send in a patch and see if
> it gets accepted :-)
>
> -k
> --
> If I haven't seen further, it is by standing in the footprints of giants
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list