Is there a way to get line-number/traceback information in Haskell?
(like C's __LINE__
macro or Python's traceback.extract_stack()
)
That would be of use for me for writing Haskell program that generates C++ code, which would be notated with comments telling which Haskell line is responsible for which C++ line.
Haskell example:
LINE "#include <foo.h>" -- this is line 12
: INDENT "void Foo::bar() {" "}"
[ LINE $ "blah(m_" ++ x ++ ", \"" ++ x ++ "\");"
| x <- ["Potato", "Avocado"]
]
will generate this C++ code:
#include <foo.h> // gen.hs:12
void Foo::bar() { // gen.hs:13
blah(m_Potato, "Potato"); // gen.hs:14
blah(m_Avocado, "Avocado"); // gen.hs:14
} // gen.hs:13