开发者

Multiline error message reporting in 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 
               开发者_如何学C       some more blah in this line also."

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


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.


you can just concatenate the strings:

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.")

this works for me

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜