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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:32:04+00:00 2026-05-28T13:32:04+00:00

I need a loop for main in Haskell. I’ve tried this: main :: IO

  • 0

I need a loop for main in Haskell. I’ve tried this:

main :: IO ()
main =
  do
    putStrLn "do something"
    main

Is the above code the correct approach to take? Will this infinite recursion cause an overflow?

  • 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-28T13:32:05+00:00Added an answer on May 28, 2026 at 1:32 pm

    This is fine; no stack overflow will occur. Stack overflows in Haskell (and, indeed, any non-strict language) are different to those in other languages; they arise from accumulating large values without ever evaluating them, but you’re not accumulating anything here; just sequencing an infinite chain of actions. You can think of it like this: Once the line is printed, the action is discarded, and control passes straight onto main; nothing is kept on the stack because there’s nothing that has to be returned to.

    It’s the same reason you can iterate through an infinite list without running out of memory: as the program goes further down the list, previous list cells are reclaimed by the garbage collector as they’re no longer required. In this case, the previous sequencings are reclaimed, as there’s no reason to keep around an action you’ve already performed.

    That said, a nicer way to write this particular example is:

    import Control.Monad
    
    main :: IO ()
    main = forever $ putStrLn "do something"
    

    Of course, this won’t work if your loop is ever intended to terminate. forever is itself implemented with recursion, so there’s no benefit other than readability to doing this.

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

Sidebar

Related Questions

i have the following code ..i need to loop through end of the file
I need to write some code that would loop though all rows of a
I'm working in a service whose main loop looks like this: while (fServer.ServerState =
My java / jython app runs a ‘default’ SWT main loop like this: while
I need to loop through all the matches in say the following string: <a
I need to loop through a set of 2-dimensional array of hidden input fields
I need to loop over a query exactly 12 times to complete rows in
I have a number rather large, complex xml documents that I need to loop
I need a for loop which would print from year 2000 to 2099. [Bindable]
The XML feed is located at: http://xml.betclick.com/odds_fr.xml I need a php loop to echo

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.