Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:07:05+00:00 2026-06-12T10:07:05+00:00

I have a file with some data in it. This data never changes and

  • 0

I have a file with some data in it. This data never changes and I want to make it available outside of the IO monad. How can I do that?

Example (note that this is just an example, my data is not computable):

primes.txt:

2 3 5 7 13

code.hs:

primes :: [Int]
primes = map read . words . unsafePerformIO . readFile $ "primes.txt"

Is this a “legal” use of unsafePerformIO? Are there alternatives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:07:06+00:00Added an answer on June 12, 2026 at 10:07 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file containing some data (for example, 00927E2B112DB958......). This data is a
I have some data and need to create a json file with this structure
I have a file, where I want to copy some data of the file
So what I have is a MS Word docx file that contains some data
I have one problem , I want to get some data from XML file
I have some configuration data in a config file that I read off disk
I have some data that I export into an XML file and put in
I did it before... But I forgot. I have a file with some data:
i have an form which will send some data to an php file ,
i am getting problem as i have some data in a database tabel file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.