跟踪Haskell中的错误 [英] Tracking down errors in Haskell

查看:96
本文介绍了跟踪Haskell中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得有关Haskell错误发生地点的更多信息?例如,昨天我正在研究一个Haskell程序,它解析输入文件,转换数据,然后打印出报告信息。



有一次,我跑了main 并返回

  *** Prelude.read:解析错误

没有其他信息。幸运的是,我知道我只是在一个地方打电话给读者,并且能够解决它,但对于未来:


  • 是否有可能得到一个回溯或行号为这样的错误?

  • 是否有可能获得触发错误的实际数据,即导致解析错误的字符串? b

    $ b

    谢谢!



    编辑使用GHC。

    解决方案

    您可以通过导入 Debug.Trace 并更改
    您的呼叫

     
    import Debug.Trace(trace)

    - change
    myRead s = read s
    --to
    myRead s = trace s(读取s)
    - 或
    myRead s = trace(花费100 s)(读取s)


    How can I get more information about where a Haskell error has occurred? For example, yesterday I was working on a Haskell program that parses an input file, transforms the data and then prints out reporting information.

    At one point, I ran "main" and got back

    *** Prelude.read: parse error
    

    with no other information. Fortunately, I knew I was calling read in only one place and was able to fix it, but for the future:

    • Is it possible to get a backtrace or a line number for errors like these?
    • Is it possible to get the actual data that triggered the error, i.e. the string that caused the parse error?

    Thanks!

    Edit Using GHC.

    解决方案

    you can get the string that caused the parse error by importing Debug.Trace and changing your call

    import Debug.Trace (trace)
    
    --change
    myRead s = read s
    --to 
    myRead s = trace s (read s)
    --or 
    myRead s = trace (take 100 s) (read s)
    

    这篇关于跟踪Haskell中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆