Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you include a multiline number in a Haskell source file?

Tags:

syntax

haskell

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?

like image 845
user668074 Avatar asked Dec 31 '22 21:12

user668074


1 Answers

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
like image 113
chi Avatar answered Apr 17 '23 13:04

chi