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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:53:23+00:00 2026-06-15T23:53:23+00:00

This question is certainly for stackoverflow.com here is the sample module Main where import

  • 0

This question is certainly for stackoverflow.com

here is the sample

module Main where

import Control.Monad.Random
import Control.Exception

data Tdata = Tdata Int Int Integer String

randomTdata :: (Monad m, RandomGen g) => RandT g m Tdata
randomTdata = do
  a <- getRandom
  b <- getRandom
  c <- getRandom
  return $ Tdata a b c "random"


manyTdata :: IO [Tdata]
manyTdata = do
  g <- newStdGen
  evalRandT (sequence $ repeat randomTdata) g

main = do
  a <- manyTdata
  b <- evaluate $ take 1 a
  return ()

after compilation this return

Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize -RTS' to increase it

How can it happen ? Is MonadRandom not lazy or what else ? And how to define the cause of stack overflow in cases like that ?

  • 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-15T23:53:24+00:00Added an answer on June 15, 2026 at 11:53 pm

    The issue arises because you are building IO into your manyTdata function.
    The monad transformer ends up being of type RandT g IO Tdata. Because each element of
    your infinite list can consist of IO actions, the entirety of the infinite list
    returned by manyTdata must be evaluated completely before the function can return
    any results.

    The simplest solution would be to use Rand instead of RandT, as using the tranformer
    isn’t really useful here, anyway; you could also change the base monad to something like
    the Identity monad by changing manyTdata to

    manyTdata :: IO [Tdata]
    manyTdata = do
      g <- newStdGen
      return $ runIdentity $ evalRandT (sequence $ repeat randomTdata) g
    

    Which will terminate in a finite amount of time. The error concerning your stack size
    is simply a result of recursively expanding your list of IO actions. Your code says to sequence all of these actions, so they all have to be performed, it has nothing to do with laziness.

    Something else to think about, rather than using randomTdata, consider
    making Tdata an instance of the Random class.

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

Sidebar

Related Questions

I just finished looking at this question: https://stackoverflow.com/questions/753122/which-cloud-computing-platform-should-i-choose But, I am not certain what
This isn't strictly a programming question, but I'm asking it here because it's certainly
I'm looking at some code with this form: 1 package com.stackoverflow.java.questions; 2 import java.util.ArrayList;
This question relates to https://stackoverflow.com/questions/9603/what-is-some-great-source-code-to-read which compiles a list of great (in the sense
In this example https://stackoverflow.com/a/9980346/93647 and here Why is my disruptor example so slow? (at
I've read this: https://stackoverflow.com/questions/631850/how-do-you-name-your-many-to-many-relationship-tables But my question is a little different. I'm just wondering
this question is certainly newbie-generated. When I installed Apache and Passenger to work I
This is almost certainly a very silly question, but for some reason I'm having
Ok, so this may be a bit of a silly question, and there's certainly
I was just looking at this stackoverflow question: Display web browser settings And that

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.