我无法将数据文件打包成cabal dist。安装程序包后,使用getDataFileName
生成的目录不存在。
Main.hs:
module Main (
main
) where
import Paths_mypackage
main = do file <- getDataFileName "mydata.txt"
putStrLn file
print =<< readFile file
mypackage.cabal(浏览文件后由Leksah生成):
data-files: /Users/peter/Documents/haskell/mypackage/data/mydata.txt
mydata-dir: ""
输出:
mypackage: /Users/peter/.cabal/share/mypackage-0.0.1/mydata.txt: openFile: does not exist (No such file or directory)
/Users/peter/.cabal/share/mypackage-0.0.1/mydata.txt
答案 0 :(得分:4)
.cabal文件中的行应为
data-files: mydata.txt
data-dir: data
然后,cabal会将数据文件安装在适当的位置,/Users/peter/.cabal/share/mypackage-0.0.1/mydata.txt
,并且程序可以运行。