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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:46:34+00:00 2026-06-11T11:46:34+00:00

I’m just totally confused with lists and monads, so maybe my question isn’t correct

  • 0

I’m just totally confused with lists and monads, so maybe my question isn’t correct or very naive.
I’ve seen the way to do it using mapM_ func here:

mapM_ print [1, 2, 3, 4]

But I don’t know exactly how it works and want to know how can I do this in a way like this:

x <- [1, 2, 3]
print x

or, if I understood it right:

[1, 2, 3] >>= print

I understand that [1, 2, 3] has type [a] and print has type Show a => a -> IO (). Also I understand that for using monad List we need type List a on the left and func with type a -> List b on the right. Am I right?
Can you help me with this?

UPD. Thanks @MathematicalOrchid for explanation how mapM_ works. From my side I want to explain that the real problem is not printing any results in different lines but do some monadic actions(because now I’m hanging around OpenGL stuff) in a way monad List provides it. But I got that the root of misunderstanding was in mixing monads.

UPD2. Thanks everyone for answers. I apologize for this kinda fuzzy question. I dind’t exactly know what answer I need and what is the question. It’s because I didn’t understand some basics. So it’s hard to choose “the correct answer” now because every answers have a small peace of what I was looking for. I’ve decided to choose the closest(although not the most useful now) to what I wanted.

  • 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-11T11:46:36+00:00Added an answer on June 11, 2026 at 11:46 am

    What you want cannot work this way since you are trying to mix two monads together:

    do x <- [1,2,3]
       print x
    

    Specifically you are mixing the IO and the [] monads. In do-notation, all the statements should have the type m a for some Monad m. But in the above code, the first statement has the type [Integer] while the second statement has the type IO ().

    To get the effect you want you should use the ListT monad transformer. Monad transformers allow mixing monads together in a certain order in a stack and combining their effects as needed.

    import Control.Monad.Trans
    import Control.Monad.Trans.List
    
    value = do x <- ListT (return [1,2,3])
               lift (print x)
    

    This will return a value of type ListT IO Integer. To get the IO computation out of this transformer, use runListT. Which will return a value of type IO [Integer]. This will output:

    GHCI> runListT value
    1
    2
    3
    [(),(),()]
    

    Which is equivalent to mapM print [1,2,3]. To throw away the list and get the effect of mapM_ print [1,2,3] you can use void from Control.Monad.

    GHCI> void . runListT $ value
    1
    2
    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I don't have much knowledge about the IPv6 protocol, so sorry if the question

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.