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

  • SEARCH
  • Home
  • 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 4018112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:56:34+00:00 2026-05-20T09:56:34+00:00

In my Haskell program, I want to read in a value given by the

  • 0

In my Haskell program, I want to read in a value given by the user using the getLine function. I then want to use the read function to convert this value from a string to the appropriate Haskell type. How can I catch parse errors thrown by the read function and ask the user to reenter the value?

Am I right in thinking that this is not an “IO Error” because it is not an error caused by the IO system not functioning correctly? It is a semantic error, so I can’t use IO error handling mechanisms?

  • 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-20T09:56:35+00:00Added an answer on May 20, 2026 at 9:56 am

    You don’t want to. You want to use reads instead, possibly like that:

    maybeRead = fmap fst . listToMaybe . reads
    

    (though you might want to error out if the second element of the tuple is not "", that is, if there’s a remaining string, too)

    The reason why you want to use reads instead of catching error exceptions is that exceptions in pure code are evil, because it’s very easy to attempt to catch them in the wrong place: Note that they only fly when they are forced, not before. Locating where that is can be a non-trivial exercise. That’s (one of the reasons) why Haskell programmers like to keep their code total, that is, terminating and exception-free.

    You might want to have a look at a proper parsing framework (e.g. parsec) and haskeline, too.

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

Sidebar

Related Questions

I am trying to use hSetBuffering in a Haskell program using GHC 6.10. When
I want to use a Haskell function with the following type :: string ->
I'm using getArgs in my Haskell program to parse arguments from the command line.
If using Haskell as a library being called from my C program, what is
I ported a little Haskell program I wrote from Mac to Windows. It's a
I want to do a popen() / python's subprocess.communicate from Haskell - start a
I want to convert my single file program - which contains the data (
I want to use Haskell in production. It has a lot of libraties but
I'm using the parsec Haskell library. I want to parse strings of the following
I want to make a haskell program where some shape is drawn in a

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.