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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:07:20+00:00 2026-05-30T08:07:20+00:00

I have this snippet of a function: mapM (\x -> do t’ <- t;

  • 0

I have this snippet of a function:

mapM (\x -> do t' <- t; return $ strSwop "if0" ("if" ++ show x) t') [0..(n-1)]

With

strSwop :: String -> String -> String -> String
t :: IO String

It works as expected but I don’t like the IO construct withing the lambda.
How can it be written differently?
I come out of the monad just to be wrapped again next line. Feels ugly.

If I do it this way:

mapM (\x -> t >>= strSwop "if0" ("if" ++ show x) t) [0..(n-1)]

It complains (obviously) about the return signature of strSwop 🙁
strSwop is just a string replacement function.
Is there a way to correctly write this?
Thanks.

— EDIT —

Just figured it out …

Works out:

mapM (\x -> liftM (strSwop "if0" ("if" ++ show x)) t) [0..(n-1)]
  • 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-30T08:07:21+00:00Added an answer on May 30, 2026 at 8:07 am

    I would suggest liftM or <$>

    import Control.Applicative
    mapM (\x -> strSwop "if0" ("if" ++ show x) <$> t) [0..(n-1)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code snippet inside a function that checks if an object exists
I have encounters this abap snippet that I have difficulty to comprehend. call function
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =
VS 2008 I have this code snippet I found on a VB website. But
I have this jQuery snippet: $(function() { $(ul > li).hover(function() { $(this).find(ul).stop(true, true).animate({opacity: 'toggle'},
I have this snippet of C code: #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct Date {
I have this javascript snippet: var selectName[id1,id2,id3]; setOnClickSelect = function (prefix, selectName) { for(var
I have a collection of lines, like in this snippet: def insertBeforeLine(text:String,whichLine:String,what:String) = {
basically i have this click function in jquery: (this is just a snippet, not
Hello I have this snippet of jQuery code jQuery(document).ready(function($) { $.get(<?echo $site['url'];?>modules/tuitting/tuitting_core/classes/count.php, function (data)

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.