[Haskell-cafe] Functor instance for FunPB

Joachim Breitner mail at joachim-breitner.de
Sat May 6 18:45:34 UTC 2017


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 at joachim-breitner.de
  http://www.joachim-breitner.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170506/6869418c/attachment.sig>


More information about the Haskell-Cafe mailing list