Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline error message reporting in Haskell

Tags:

haskell

I have a Haskell function which reports a long error message. Although I can write this message in one line, I want to break it into two or more e.g.

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

GHCi does not compile it. Any suggestion? A casual googleing did not produce any answer.

like image 884
Dilawar Avatar asked Jan 18 '23 19:01

Dilawar


1 Answers

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

foo a b | 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 it doesn't matter much, but in other contexts it can be more efficient than concatenating strings.

like image 100
John L Avatar answered Jan 28 '23 15:01

John L