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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:42:24+00:00 2026-05-17T23:42:24+00:00

I am very interested in Haskell and currently trying to solve this problem. To

  • 0

I am very interested in Haskell and currently trying to solve this problem.

To solve the problem it is necessary to output List C (x,z) that matches (x,y) from List A and (y,z) from List B (without duplicates) y must be equal in A and B.

So for example:

A = [("z","x")]
B = [("x","c"), ("x","d")] 

Result:

C = [("z","c"), ("z","d")]

Any ideas? I have started today with:

main = print(map describeList3 list_A)  

describeList3 :: ([Char], [Char]) ->Maybe [[Char]]
describeList3 element = printParam(snd element)                               

printParam :: String -> Maybe [[Char]]
printParam param = (Map.lookup param $ myFilter list_B)

myFilter :: (Ord k) => [(k, a)] -> Map.Map k [a]  
myFilter xs = Map.fromListWith (++) $ map (\(k,v) -> (k,[v])) xs  

Currently stuck… help?

  • 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-17T23:42:25+00:00Added an answer on May 17, 2026 at 11:42 pm

    List comprehensions quick and dirty solution. As for duplicates you can remove them with either nub (from Data.List), or with converting result to Data.Set and back to list.

    nub [(x,z) | (x,y) <- a, (y',z) <- b, y == y']
    

    Or with map. We create auxiliary map for list b, where value is list of values from list. And then just build for each (x,y) pair list of required (x,z) pairs (with non-nil check). Actually i think you were stuck precisely because you didn’t use list comprehensions. 🙂 Maps / filters are great for processing, but building is much easier understood in terms of list comprehensions.

    let b' = M.fromListWith (++) [(k,[v]) | (k,v) <- b]
    nub . concat $ [[(x, z) | let t = M.lookup y b', t /= Nothing, z <- fromJust t] | (x,y) <- a]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very interested in at least trying to implement NAT break through for
I'm very interested in languages and their underpinnings, and I'd like to pose this
I have very interested in using MongoDB it seems awesome. But I'm from a
I am very interested in c++ and want to master this language. I have
I am learning F# and very interested in this language I try to create
OK maybe this is a trivial issue but I'm very interested to see if
I'm very interested in how financial data is streamed from server to client. I
I'm very interested in using 4.0 framework and also the Entity Framework 4.0. Currently
I am very interested how git log -- filename works internally. Does this go
I am very interested in some studies or empirical data that shows a comparison

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.