Haskell Error Reporting

I have a Haskell function that reports a long error message. Although I can write this message on one line, I want to split it into two or more, for example.

foo ab | a > b = a | a == b = b | otherwise = error "Blah blah blah blah in this line and some more blah in this line also." 

GHCi will not compile it. Any suggestion? Random googleing did not give any answer.

+4
source share
2 answers

you can just concatenate strings:

 foo ab | a > b = a | a == b = b | otherwise = error ("Blah blah blah blah in this line and" ++ " some more blah in this line also.") 

it works for me

+3
source

You can use the ghc multi-line string syntax for this:

 foo ab | a > b = a | a == b = b | otherwise = error "Blah blah blah blah in this line and \ \some more blah in this line also." 

For errors, this does not really matter, but in other contexts it can be more efficient than string concatenation.

+6
source

All Articles