Underscore in binary literals

Rahul Muttineni rahulmutt at gmail.com
Tue Sep 26 12:58:45 UTC 2017


Implementation-wise, it's no so difficult to include - the lexer needs to
be tweaked. But it seems like a specialised use-case that will only affect
a minority of users is probably not worthwhile as an extension to the
language/compiler.

Maybe you can try using OverloadedStrings and implement this as a library?

```
newtype Binary = Binary Integer
  deriving Num

instance IsString Binary where
  fromString binaryLiteral = error "Code here to parse binary literal with
underscores"

binaryVal :: Binary
binaryVal = "1101_1110_0101"
```

Hope that helps,
Rahul

On Tue, Sep 26, 2017 at 8:40 AM, Takenobu Tani <takenobu.hs at gmail.com>
wrote:

> Dear devs,
>
> GHC's BinaryLiterals extension is useful.
> (For example, x = 0b110111000101)
>
> Is it difficult to include underscore(_) in the format like Verilog-HDL[1]
> ?
> (For example, x = 0b1101_1100_0101)
>
> [1]: https://inst.eecs.berkeley.edu/~cs150/fa06/Labs/verilog-
> ieee.pdf#page=20
>
> Regards,
> Takenobu
>
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
>


-- 
Rahul Muttineni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20170926/c32b2c39/attachment.html>


More information about the ghc-devs mailing list