<div dir="ltr">The mconcat method is also how xmonad handles its ManageHooks, which are basically Endo Monoids.</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="h5"><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_6264154254092456168HOEnZb"><div class="m_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/b<wbr>laze-markup/issues/36</a><br>
> ______________________________<wbr>_________________<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-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
<br>
</div></div><br>______________________________<wbr>_________________<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-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</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="HOEnZb"><font color="#888888">-- <br><div class="m_6264154254092456168gmail_signature" data-smartmail="gmail_signature">-Andrew Thaddeus Martin</div>
</font></span></div>
<br>______________________________<wbr>_________________<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-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_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>