Wednesday, 18 September 2013

How can I fix this program dealign with pairs of Booleans in Haskell?

How can I fix this program dealign with pairs of Booleans in Haskell?

For part of a homework assignment in a beginner Haskell course, I'm trying
to write a program that will take a list of pairs of Bools, and returns a
list of Bools coming from the pairs of bools with an "&&" between them.
For example...
andandbool [(True,True),(True,False),(False,True),(False,False)]
would return:
[True, False, False, False]
I keep running into trouble, however. My code looks like this.
andandbool :: [(Bool,Bool)] -> [Bool]
andandbool [a] = [fst x && snd x | x <- [a]]
It works fine when I provide a list of only one pair, but reports
"Non-exhaustive patterns in function andandbool" when I enter a list of
multiple pairs. Is there some sort of list comprehension that I'm missing?
Any pointers in the right direction would be greatly appreciated.

No comments:

Post a Comment