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 6644685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:11:46+00:00 2026-05-26T00:11:46+00:00

I am trying to take user input and convert it in the form of

  • 0

I am trying to take user input and convert it in the form of a list of tuples.
What I want to do is that, I need to take the data from the user and convert it in the form of
[(Code,Name, Price)] and finally combine this user input with the previous list and write the new list to the same file.

The problem I am facing is that as soon as the program completes taking user input, WinHugs is showing an error like this Program error: Prelude.read: no parse.

Here is the code:

type Code=Int
type Price=Int
type Name=String
type ProductDatabase=(Code,Name,Price)

finaliser=do
           a<-input_taker 
           b<-list_returner
           let w=a++b
           outh <- openFile "testx.txt" WriteMode
           Print outh w
           Close outh   
  • 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-05-26T00:11:46+00:00Added an answer on May 26, 2026 at 12:11 am

    The problem is that you’re using lazy IO to read from a file while you’re writing to it at the same time. This causes problems when read sees data that has been partially written.

    We need to force the reading of the input data to be complete before you try writing to the file. One way of doing this is to use seq to force the list of products to be read into memory.

    list_returner :: IO ([ProductDatabase])
    list_returner = do
        inh <- openFile "testx.txt" ReadMode
        product_text <- hGetContents inh
        let product :: [ProductDatabase]
            product = read product_text
        product `seq` hClose inh
        return product
    

    Also, this will fail if the file is empty. The file should contain at least [] before running your code the first time, so that it will parse as the empty list.

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

Sidebar

Related Questions

I was trying to make a code that will take input from a user
I'm trying to take user form input and display it back to the user,
I am trying to take numbers from three EditText boxes that the user fills
I am trying to take a single input from the user and delete some
So I'm trying to take an input from a user using Scanner(System.in) but when
I'm trying to take the user input, which may or may not have a
i'm trying to create an app that would present a form to the user
In this loop, I'm trying to take user input and continually put it in
I am trying to receive user input and then put it into a list.
I am trying to create a program that will take user inputs(marks) and output

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.