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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:36:23+00:00 2026-06-13T09:36:23+00:00

I have seen the solutions using iterate or replicate in order to apply a

  • 0

I have seen the solutions using iterate or replicate in order to apply a function n times. However, I don’t manage to use it inside a State monad.

This code works:

-- Stuff an empty game level with obstacles.
generateLevel :: Level -> State StdGen Level
generateLevel lvl =
    placeRandomWall lvl >>= placeRandomWall >>= placeRandomWall

This one works as well, unsurprisingly:

generateLevel :: Level -> State StdGen Level
generateLevel lvl =
    placeRandomWall =<< placeRandomWall =<< placeRandomWall lvl

However, this is not the same as:

generateLevel :: Level -> State StdGen Level
generateLevel lvl =
    (placeRandomWall =<< placeRandomWall =<< placeRandomWall) lvl

The latest complains about types. Therefore, I can’t foldl (=<<) id (relicate 42 placeRandomWall), nor can I iterate.

This makes sense, as iterate take a a -> a function, while what I have is a -> m a or something like that. So, I don’t really know how to go from there.

  • 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-13T09:36:24+00:00Added an answer on June 13, 2026 at 9:36 am

    I think you’re looking for <=< and >=> from Control.Monad. They can be folded across a list you’ve made with replicate to create one big action.

    Try foldr (<=<) return (replicate 42 placeRandomWall).

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

Sidebar

Related Questions

I have seen lots of questions and solutions on File upload using Selenium WebDriver
I have seen n-tiers solutions on the web, they all use DLLs for each
I have seen solutions like this: kernel dp_square (const float *a, float *result) {
i have seen some hand rolled solutions but does jquery out of the box
I have tried several of the solutions I have seen out here, but am
Dynamic queries are not dynamic enough. I have seen solutions like this but still
I have seen similar problems, but none of the solutions have worked for me.
I have seen some ListView dynamic growing implementations which use OnScrollListener. I would like
I have seen solutions to a very similar issue, yet it doesn't translate to
Of all the solutions i have seen for this they fall into 3 categories.

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.