You could use TemplateHaskell to read in the file at compile time. The data of the file would then be stored as an actual string in the program.
In one module (Text/Literal/TH.hs
in this example), define this:
module Text.Literal.TH where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
literally :: String -> Q Exp
literally = return . LitE . StringL
lit :: QuasiQuoter
lit = QuasiQuoter { quoteExp = literally }
litFile :: QuasiQuoter
litFile = quoteFile lit
In your module, you can then do:
{-# LANGUAGE QuasiQuotes #-}
module MyModule where
import Text.Literal.TH (litFile)
primes :: [Int]
primes = map read . words $ [litFile|primes.txt|]
When you compile your program, GHC will open the primes.txt
file and insert its contents where the [litFile|primes.txt|]
part is.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…