Get absolute path of current source file in Haskell
haskell
Solution
You can use CPP. If you compile this file
{-# LANGUAGE CPP #-}
main = print __FILE__
it will print the path to the source as you passed it to `ghc` – which may or may not be the full path, though:
/tmp $ ghc --make mypath.hs
[1 of 1] Compiling Main ( mypath.hs, mypath.o )
Linking mypath ...
/tmp $ ./mypath
"mypath.hs"
/tmp $ ghc --make /tmp/mypath.hs
Linking /tmp/mypath ...
/tmp $ ./mypath
"/tmp/mypath.hs"
Problem
Is it possible to get the absolute path of the current source file in Haskell? I could only find one relevant function: `getCurrentDirectory` from `System.Directory`, but it "returns an absolute path to the current directory of the calling process.", not the path of the current file. (I need it to read sample inputs which are located in the same folder as the source file; If there's any better way to do it, that will be helpful too!)