
Hi, Am Samstag, den 06.05.2017, 20:32 +0200 schrieb Alex Wede:
The monoid instance is from my teacher.
it is hard to tell with confidence, given that we do not know what FunFB is supposed to “mean”, but data FunPB a b = FunPB { runFunPB :: a -> (a,[b]) } instance Monoid (FunPB a b) where mempty = FunPB $ \k -> (k,mempty) mappend pb1 pb2 = FunPB $ \n -> (,) n $ msum . (<$>) (uncurry (flip const).((flip runFunPB) n)) $ [pb1,pb2] looks very fishy, as the return value of of type a from pb1 and pb2 are ignored in mappend The latter means that this is not a lawful monoid, because for pb = (\n -> (n+1, []) we have mempty `mappend` pb == mempty /= pb Did you maybe mean mappend pb1 pb2 = FunPB $ \n0 -> let (n1,xs1) = runFunFB n1 (n2,xs2) = runFunFB n2 in (n2, xs1 ++ xs2) Greetings, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/