I'm playing with my first non-trivial (in my eyes) attempt at something in Haskell. I'm probably going to ask questions about each part to compare my coming-from-long-term-relationship-with-c-like-languages attempt to what you-as-seasoned-functional-programmer might do. Luckily Haskell makes it hard to fall back on straight c-to-haskell code conversion. You have to learn how to do it right - and I want to.
For this part, I have a [2uple] and a 2uple. I want to know if any item in the 2uple is in any of the items in the [2uple].
hasmatch tlst tupm = foldr (\tup acc ->
let tmatch (a,b) (c,d) = a==c || b==c || a==d || b==d in
if tmatch tup tupm
then (Just True) -- short out
else acc -- do nothing, keep looping
) Nothing tlst
-- hasmatch [(1,2), (3,4), (5,6)] (5,3) ==> Just True
-- hasmatch [(1,2), (9,4), (7,6)] (5,3) ==> Nothing
I'd prefer to return a plain Bool but no biggie there.
I'm sure there is another way that I would have to grok at for a while to understand. That is good. Looking for takers.
Thanks