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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:17:37+00:00 2026-05-26T23:17:37+00:00

I have a main function that does a lot of IO. At one point,

  • 0

I have a main function that does a lot of IO. At one point, however, I want to check a variable like not (null shouldBeNull) exit the whole program, without continuing, with a linux exitcode 1 and output an error message.

I’ve tried playing around with error "..." like putting that in an if:

if (not (null shouldBeNull)) error "something bad happened" else putStrLn "ok"

but I get a parse error (possibly incorrect indentation) :(.

Here’s an altered snippet.

main :: IO ExitCode
main = do 
  --Get the file name using program argument
  args <- getArgs
  file <- readFile (args !! 0)
  putStrLn("\n")
  -- ... (some other io)
  -- [DO A CHECK HERE], exit according to check..
  -- ... (even more io)
  echotry <- system "echo success"
  rmtry <- system "rm -f test.txt"
  system "echo done."

As you may notice, I want to do the check where I’ve put [DO A CHECK HERE] comment above…

Thanks for your help!

  • 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-26T23:17:37+00:00Added an answer on May 26, 2026 at 11:17 pm

    The parse error is because you’re missing the then keyword in your if expression.

    if condition then truePart else falsePart
    

    For exiting, a more appropriate choice than error might be to use one of the functions from System.Exit, for example exitFailure.

    So for example,

    if not $ null shouldBeNull
        then do putStrLn "something bad happened"
                exitFailure
        else putStrLn "ok"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have a function that does not interfere with other data and runs
I have a main thread that invokes a child thread function at different times
I have a web project that I developed where one of the main functions
Im looking to have a common parent function like so void main (param 1,
If I have a function that contains a lot of print statements: ie. def
In a C project, I have a main() function in several files. When I
Okay here's the program I have typed up(stdio.h is included also): /* function main
I have a function thats the main bottleneck of my application, because its doing
I have a function to load a html part into a element in main
I have a number of iframes calling a function in my main page. Is

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.