如何在Haskell中使用行号和堆栈跟踪进行打印? [英] How to print with line number and stack trace in Haskell?

查看:129
本文介绍了如何在Haskell中使用行号和堆栈跟踪进行打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把Java添加到了我的打印语句中,并且他们有一个堆栈跟踪...



我们如何将行号打印到java日志中

  public static int getLineNumber(){
//堆栈跟踪的第二行包含调用者文件名等。
return Thread。 。currentThread()的getStackTrace()[2];
}

我如何做Haskell?


Debug.Trace:


$ b

traceStack :: String - > a - > a来源



类似跟踪,但是另外打印一个调用堆栈(如果有的话)。



在当前的GHC实现中,只有
该程序使用-prof编译;否则traceStack的行为跟
完全一样。调用堆栈中的条目对应于SCC
注释,因此使用-fprof-auto或
-fprof-auto-calls自动添加SCC注释是一个不错的主意。



自:4.5.0.0


^ https://hackage.haskell.org/package/base-4.8.2.0/docs/Debug-Trace.html


I Java I appended this to my print statements and they had a stack trace...

How can we print line numbers to the log in java

public static int getLineNumber() {
    // The second row of the stack trace had the caller file name, etc.
    return Thread.currentThread().getStackTrace()[2];
}

How do I do this is Haskell?

解决方案

I think I found a solution:

Debug.Trace: Functions for tracing and monitoring execution.

traceStack :: String -> a -> a Source

like trace, but additionally prints a call stack if one is available.

In the current GHC implementation, the call stack is only availble if the program was compiled with -prof; otherwise traceStack behaves exactly like trace. Entries in the call stack correspond to SCC annotations, so it is a good idea to use -fprof-auto or -fprof-auto-calls to add SCC annotations automatically.

Since: 4.5.0.0

^ https://hackage.haskell.org/package/base-4.8.2.0/docs/Debug-Trace.html

这篇关于如何在Haskell中使用行号和堆栈跟踪进行打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆