<div dir="ltr">Another mconcat user here. The only place it does fall down a bit is when you want something to be optional. In a monad we have `when`, but I don't know of any similar combinator for monoids. Of course, it's just `if x then y else mempty`, but I always end up defining a when-like function over and over again.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 9, 2018 at 12:53 AM Brandon Allbery <<a href="mailto:allbery.b@gmail.com">allbery.b@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The mconcat method is also how xmonad handles its ManageHooks, which are basically Endo Monoids.</div><div class="gmail_extra"></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 8, 2018 at 8:48 AM, Andrew Martin <span dir="ltr"><<a href="mailto:andrew.thaddeus@gmail.com" target="_blank">andrew.thaddeus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I do the same thing that <span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;white-space:nowrap;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Merijn does. It works really well.</span></div><div class="gmail_extra"><div><div class="m_-8249350874519689629h5"><br><div class="gmail_quote">On Thu, Mar 8, 2018 at 8:08 AM, Merijn Verstraaten <span dir="ltr"><<a href="mailto:merijn@inconsistent.nl" target="_blank">merijn@inconsistent.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I always just use mconcat and lists, so instead of:<br>
<span>> complicatedValue = execWriter $ do<br>
>  component1<br>
>  component2<br>
>  modifier $ do<br>
>    component3<br>
>    component4<br>
<br>
</span>I write:<br>
<br>
complicatedValue = mconcat<br>
    [ component1<br>
    , component2<br>
    , modifier . mconcat $ [component3, component4]<br>
    ]<br>
<br>
Alternatively, if component3 and component4 are really long or lots of them linewrap those too:<br>
<br>
complicatedValue = mconcat<br>
    [ component1<br>
    , component2<br>
    , modifier . mconcat $<br>
        [ component3<br>
        , component4<br>
        ]<br>
    ]<br>
<br>
Cheers,<br>
Merijn<br>
<div class="m_-8249350874519689629m_6264154254092456168HOEnZb"><div class="m_-8249350874519689629m_6264154254092456168h5"><br>
> On 8 Mar 2018, at 14:02, Olaf Klinke <<a href="mailto:olf@aatal-apotheke.de" target="_blank">olf@aatal-apotheke.de</a>> wrote:<br>
><br>
> Dear cafe,<br>
><br>
> prompted by a discussion with the author of blaze-markup [1] I realized a pattern and would like to know whether other haskellers have exploited this/find this useful:<br>
><br>
> For every monoid m, the types Writer m () and m are isomorphic as types via tell and execWriter. Moreover, Writer m is a monad if and only if m is a monoid. For every monad t, the type t () is a monoid with<br>
>   mempty = return ()<br>
>   mappend = (>>).<br>
> In the particular case of Writer m () and m, the isomorphism of Haskell types is in fact an isomorphism of monoids, that is, the functions tell and execWriter preserve the monoid operations.<br>
><br>
> This enables us to use do-notation in building complicated values of any monoid type, e.g. Text or any other syntax. Instead of writing<br>
><br>
> complicatedValue = component1 <><br>
>  component2 <><br>
>  modifier (component3 <> component4)<br>
><br>
> one can write<br>
><br>
> complicatedValue = execWriter $ do<br>
>  component1<br>
>  component2<br>
>  modifier $ do<br>
>    component3<br>
>    component4<br>
><br>
> Should such an idiom be encouraged/discouraged? How do you handle the construction of monoid values (especially text-like) with interspersed function applications (e.g. show, prettyprint)?<br>
><br>
> Regards,<br>
> Olaf<br>
><br>
> [1] <a href="https://github.com/jaspervdj/blaze-markup/issues/36" rel="noreferrer" target="_blank">https://github.com/jaspervdj/blaze-markup/issues/36</a><br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> To (un)subscribe, modify options or view archives go to:<br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
<br>
</div></div><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="m_-8249350874519689629HOEnZb"><font color="#888888">-- <br><div class="m_-8249350874519689629m_6264154254092456168gmail_signature" data-smartmail="gmail_signature">-Andrew Thaddeus Martin</div>
</font></span></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br><br clear="all"><div><br></div></div><div class="gmail_extra">-- <br><div class="m_-8249350874519689629gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div></div>
</div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>