[Haskell-beginners] a simple problem

Anonymous W w_anonymous at ymail.com
Wed Nov 3 18:31:09 EDT 2010

I'm having trouble with this small exercise. 
A function maybeA takes a list of pairs. A pair has a variable 'a' and a value 
'b'. If any first element of a pair equals to any first element of another pair, 
the function returns Nothing. If they aren't equal, the function returns a tuple 
containing the first variable, its value and the value of the second variable.
maybeA :: [(a,b)] -> Maybe (a,b,b)

For example:  [(a1,b1),(a2,b2),(a3,b3)..] returns Nothing if a2 = a3 and returns 
Just (a2,b2,b3) if  a2 /= a3
I'm currently have :maybeA [(a1,b1),(a2,b2)] 
    |a1 == a2 = Nothing
    |a1 /= a2 = Just (x1,y1,y2)
but it only takes 2 pairs. Any helps?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20101103/3b6161ca/attachment.html

More information about the Beginners mailing list