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 want to use a Haskell function with the following type :: string ->
I want to do a popen() / python's subprocess.communicate from Haskell - start a
Haskell is givinig me a headache today. I want to handle an exception. When
From the haskell report: The quot, rem, div, and mod class methods satisfy these
For a tool I'm writing ( http://hackage.haskell.org/package/explore ) I need a way to read
I have some troubles with Haskell's type system. Situation: Following program is taking list
I am solving some problems of Project Euler in Haskell. I wrote a program
In Haskell, is there a way to restrict a monad M a so that
I know a Haskell module name, but I can't figure out in what package
I'm currently learning Haskell, Which language (F# or Haskell) do you prefer for programming

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.