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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:04:22+00:00 2026-06-04T21:04:22+00:00

Been scratching my head for a day over this one. I have a few

  • 0

Been scratching my head for a day over this one.

I have a few functions in my code that look like this:

function :: IO (Maybe Whatever)
function = do
   monadFun
   yaySomeIO
   status <- maybeItWillFail
   if checkStatus status  -- Did we succeed?
   then monadTime >>= return . Just . processItPurely
   else return Nothing

ghci will load and run this interactively with no problems, and ghc will compile it happily.
Running this through cabal, however, gives me this:

myProgram.hs:94:16:
Unexpected semi-colons in conditional:
    if checkStatus status; then monadTime >>= return . Just . processItPurely; else return Nothing

Perhaps you meant to use -XDoAndIfThenElse?

And whatever this -XDoAndIfThenElse option is, I can’t seem to find a trace of it anywhere in any documentation.
Why is cabal (or is this ghc by this point?) yelling at me for using semi-colons that IT put there in the first place? Or is using monadic expressions in if-then-else statements just a bad idea?

Note that cabal doesn’t complain about this at all:

case checkStatus status of
   True -> monadTime >>= return . Just . processItPurely
   _    -> return Nothing

…except this is ugly as hell and I’d never want to put this in my code.
Can anyone tell me what’s going on? Please and thanks in advance.

  • 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-04T21:04:24+00:00Added an answer on June 4, 2026 at 9:04 pm

    The “correct” way of indenting if-expressions in a do-block is to indent the else and then lines further than the if, like this.

    function = do
       monadFun
       yaySomeIO
       status <- maybeItWillFail
       if checkStatus status  -- Did we succeed?
          then monadTime >>= return . Just . processItPurely
          else return Nothing
    

    This is because lines with the same amount of indentation in a do block are normally treated as separate statements.

    However, there is an extension called DoAndIfThenElse which will allow you to write it the way you did. This extension was made standard in Haskell 2010, which is why GHC enables it by default.

    Cabal tends to require you to be more explicit about these things, so to use it in Cabal, you need to either mention it in your .cabal file or add {-# LANGUAGE DoAndIfThenElse #-} to the top of your module.

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

Sidebar

Related Questions

This one is quite tricky i've been scratching my head all day. I have
Okay guys, I have been scratching my head like mad over this issue and
I've been scratching my head over this for an hour... I have a list
I have been scratching my head for a while on this one. I dont
I have been scratching my head over this for days and I still cannot
I've been scratching my head over this for the last few days and neither
I've been scratching my head over this one for a couple hours now, I've
I have been scratching my head on this one for a while, so I
I have been scratching my head on this one for some time now and
I have been scratching my head for hours trying to figure out why this

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.