Including data files in prefabricated assemblies

I have a package with the following structure (well, this is greatly simplified, but ...)

app/ src/ Main.hs data/ data.txt app.cabal Paths_app.hs Setup.hs 

In Paths_app.hs, I have:

 module Paths_app where getDataFileName :: FilePath -> IO FilePath getDataFileName = return 

and in Main.hs I have:

 module Main where import Paths_app main = do file <- getDataFileName "data/data.txt" data <- readFile file putStrLn $ "Your data is: " ++ data 

the relevant parts of my app.cabal file are as follows:

 name: app version: 1.0 build-type: Simple data-files: data/data.txt executable foo build-depends: base, haskell98 main-is: Main.hs hs-source-dirs: src 

This builds fine (using cabal configure followed by cabal install ), but the executable complains that it cannot find the data.txt file. I tried replacing the string

 file <- getDataFileName "data/data.txt" 

from

 file <- getDataFileName "data.txt" 

but the same thing happens. Is there something obvious I'm doing wrong?

+8
haskell cabal
source share
2 answers

The problem was that I was based on a Windows system, and when I used the file name returned by getDataFileName to load data into my program, I did not escape the backslashes.

+1
source share

I tried to reproduce it, but it works great for me.

In the described setup, I had to drop the dependency on haskell98 , since base and haskell98 provided Prelude . In addition, the Main file will not compile because it used the data keyword as the name of the variable, so I renamed the variable to dat . But then it worked perfectly.

Some information about my setup:

 $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.4.1 $ cabal --version cabal-install version 0.13.3 using version 1.14.0 of the Cabal library $ ls ~/.cabal/bin/ ... foo ... $ ls ~/.cabal/share/app-1.0/data/ data.txt 
+1
source share

All Articles