How to debug Haskell code?

后端 未结 4 512
渐次进展
渐次进展 2020-12-04 11:06

I have a problem. I wrote a big Haskell program, and it always works with small input. Now, when I want to test it and generate a bigger input, I always get the message:

4条回答
  •  天涯浪人
    2020-12-04 11:40

    You can use this library: Debug.Trace

    You can replace any value a with the function:

    trace :: String -> a -> a

    unlike putStrLn there is no IO in the output, e.g.:

    >>> let x = 123; f = show
    >>> trace ("calling f with x = " ++ show x) (f x)
    calling f with x = 123
    123
    

    The trace function should only be used for debugging, or for monitoring execution. The function is not referentially transparent: its type indicates that it is a pure function but it has the side effect of outputting the trace message.

提交回复
热议问题