Вопрос

I can't get data files to be packaged up in a cabal dist. The directory that is produced with getDataFileName doesn't exist after installing the package.

Main.hs:

module Main (
    main
) where

import Paths_mypackage

main = do file <- getDataFileName "mydata.txt"
          putStrLn file
          print =<< readFile file

mypackage.cabal (generated by Leksah after browsing for the file):

 data-files: /Users/peter/Documents/haskell/mypackage/data/mydata.txt
 mydata-dir: ""

Output:

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
Это было полезно?

Решение

The lines in the .cabal file should be

data-files: mydata.txt
data-dir:   data

Then cabal will install the data file in the appropriate location, /Users/peter/.cabal/share/mypackage-0.0.1/mydata.txt in your case, and the programme will work.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top