I would like to paste in a large number constant into my Haskell code, and for readability I would like to have it formatted over several lines instead of one line.
Is this possible?
This is a possible approach. I'm not completely sure about it, though. There might be an easier way.
largeConstant :: Integer
largeConstant = read $
"12345" ++
"12345" ++
"12345"
Alternatively, we could use multiline string literals, even though they are not very commonly used in Haskell.
largeConstant :: Integer
largeConstant = read
"12345\
\12345\
\12345"
Enabling CPP is also an option, but seems a bit overkill.
largeConstant = 12345\
12345\
12345
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With