Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function join :: Eq a => [(a,b)] -> [(a,c)] -> [(a,b,c)]. join takes two

ID: 3836836 • Letter: W

Question

Write a function join :: Eq a => [(a,b)] -> [(a,c)] -> [(a,b,c)]. join takes two lists of pairs, and returns a single list of triples. A triple is generated only when there exists a member of both argument lists that have the same first element. The list elements are not sorted. This is the same semantics as the relational algebra natural join operation.

For example:
join [(2,"S"),(1,"J")] [(2,True),(3,False)]

will output: [(2,"S",True)]

join [(2,"S"),(1,"J")] [(2,1),(2,2),(3,4)] will output: [(2,"S",1),(2,"S",2)]

language is haskell

Explanation / Answer

Answer:

The function join which takes two lists of pairs and returns a single list of triples is given as below :

join :: Eq a => [(a,b)] -> [(a,c)] -> [(a,b,c)]
join [] q = error "join: The list of pairs which are at the begining must be not be empty"
join p [] = error "join: The list of pairs which are at the begining must be not be empty"

By utilising comprehension list verify if p1 is equal to any of the value of q1 then append q2
join p q = [(p1, p2, q2) | (p1, p2) <- x, (q1, q2) <- q, p1 == y1]

(or)

prelude>[p*2/p<-[1...10],p*2>=12]

join[(p,p+1),(p,p+2)]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote