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

This is not yet particularly programing related but, I am very interested in how
I'm very interested in what F# has to offer and I'm very keen to
I am very interested in streaming data for web-applications. I have tried out some
My 11 year old son is very interested in programming. He has been working
Very simply put: I have a class that consists mostly of static public members,
I'm rather new to Haskell. The problem is to find the sum of all
I've been looking at Haskell lately and it seems like a very nice way
I am very interested in changing the way I tackle applications to integrate TDD
I am very interested in learning what features people are interested in in the
I am very interested in human computer interactions and mainly web interaction. Can you

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.