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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:37:32+00:00 2026-05-26T08:37:32+00:00

So I have the following list of tuples and a string type M a

  • 0

So I have the following list of tuples and a string


type M a = [(String, String)]
m = [
    ("x", "a car"),
    ("y", "a animal")
]
s = "this is x and y"

I am trying to

strRep m s => “this is a car and a animal”

So this is my attempt so far


import Data.List.Utils

strRep :: (Show a) => M -> String -> String
strRep [] s = s
strRep (m:ms) s = replace (fst m) (snd m) s : strRep ms s

The above code returns a list of string. I cant quite figure out the proper way to do loop here.

  • 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-26T08:37:32+00:00Added an answer on May 26, 2026 at 8:37 am

    I’m not sure where replace is coming from in your example above. But… assuming it exists, and does what you expect, you should be able to remove the cons (:) from your strRep function, and instead pass the result of replace into the next run of strRep, like so:

    strRep :: (Show a) => M -> String -> String
    strRep [] s = s
    strRep (m:ms) s = strRep ms (replace (fst m) (snd m) s)
    

    Now, instead of returning a list of strings, each a version with one thing replaced. You are iteratively replacing each string, passing the new strings on for the next replacement.

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

Sidebar

Related Questions

I have the following list of tuples: items = [ ('john jones', ['Director', 'Screenwriter',
I have a list of tuples similar to this: l = [(1, 2), (3,
I have a series of data points (tuples) in a list with a format
I have the following list in Python: [('1','2','3'),('5','6','7')] I need to convert the tuples
I have the two following lists: # List of tuples representing the index of
I have a list of tuples int*string where int is level and string is
I have the following snippet: import qualified Data.Vector as V import qualified Data.ByteString.Lazy as
Consider the following problem: given a list of length three of tuples (String,Int), is
I have a 3-tuple list like the following [I added line breaks for readability]:
I have the following List<int> collection and I need to find the highest integer

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.