I am trying to define an instance:
newtype Join a = Join { getJoin :: a -> Bool }
deriving Generic
instance Monoid (Join a) where
f <> g = ???
mempty = ???
The goal is that the function foldMap Join should return True if all functions in the list are true, and false if all are not true.
I understand foldMap, and the instances of Sum and Product for Monoid but am otherwise quite new to writting newtype instances of Monoid. Any help in the right direction would be appreciated. Thank you.
You can make an new function that returns
True
if both the first and second function returnTrue
, by using(&&)
. Then themempty
is aJoin
function that isTrue
for all input:Since the introduction of the
Semigroup
, the(<>)
function is an instance of theSemigroup
however: