And here is a proof that Semigroup is sufficient for flatMap:
https://scalafiddle.io/sf/JBQL0Oh/0


On Wed, Sep 27, 2017 at 12:53 PM, Tony Morris <[email protected]> wrote:

> You need Monoid to write the monad instance for Writer. What would pure
> look like without the Monoid identity?
>
> However, you only need Semigroup to use flatMap (the Bind typeclass). The
> Writer instance for Bind should only require Semigroup.
>
> On 27/09/17 20:30, Przemysław Pokrywka wrote:
>
> Hello,
>
> I've set up some monad transformer stack involving WriterT, using some
> custom data type as the Writer "log".
> I've provided a Semigroup instance for that "log" data type.
> When I try to call flatMap, the compiler tells me, that there's no
> implicit Monad instance for my stack type.
> The issue disappears when I provide a Monoid for my custom "log" type
> (instead of the Semigroup).
> I think this is related to the following code fragment:
> https://github.com/scalaz/scalaz/blob/5d6fbf7d4d567cb736a4cc2d46fc9e
> dc071cc5cf/core/src/main/scala/scalaz/WriterT.scala#L192
> and I started to wonder, why is the Monoid instance required - wouldn't
> just Semigroup be sufficient?
>
> Regards,
> Przemek
>
> --
> You received this message because you are subscribed to the Google Groups
> "scalaz" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/scalaz.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "scalaz" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/scalaz.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/d/optout.

Reply via email to