Haskell equivalent of C's __LINE__
Question: 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
    


Answer: You can actually use the CPP `__LINE__` pragma in Haskell.

    
    
    {-# LANGUAGE CPP #-}
    
    main = do
        print "one"
        print __LINE__
    
    
    $ runhaskell A.hs
    "one"
    5
    

Also, the `Control.Exception.assert` function will emit a line number if its
condition fails.

    
    
    import Control.Exception
    
    main = do
        print "one"
        assert False $
            print "two"
    
    
    $ runhaskell A.hs
    "one"
    A.hs: A.hs:5:5-10: Assertion failed
    

