Here's one option. If there are no elements in the list, then their conjunction is True
by convention. So you have
conjunction [] = True
If there is more than one element, the conjunction is True
if that element is True
, and the conjunction of all the other elements are True
conjunction (x:xs) = x && conjunction xs
This particular pattern (iterating through a list one element at a time, and combining with a binary function) is very common in function programming. In fact, it's so common that there is a helper function for it, called foldr
. So you could write
conjunction xs = foldr (&&) True xs
where the first argument specifies the combining function, and the second argument specifies the value when the list is empty.
Or you could just use an already defined function, like
conjunction = and