Skip to content

Commit 4aa2b04

Browse files
committed
Respond to comment
1 parent b2368e3 commit 4aa2b04

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

_posts/2019-04-15-lazy-monoids.html

+37
Original file line numberDiff line numberDiff line change
@@ -476,4 +476,41 @@ <h2 id="comments-header">
476476
</div>
477477
<div class="comment-date">2025-02-25 18:40 UTC</div>
478478
</div>
479+
480+
<div class="comment" id="f6a9ef03acc848849ea6c8bc54b235d9">
481+
<div class="comment-author"><a href="/">Mark Seemann</a> <a href="#f6a9ef03acc848849ea6c8bc54b235d9">#</a></div>
482+
<div class="comment-content">
483+
<p>
484+
Ian, thank you for writing. I agree that there's some hand-waving going on in that article. To make a long story short, that particular code base also includes this overload of <code>Apply</code>:
485+
</p>
486+
<p>
487+
<pre><span style="color:blue;">public</span>&nbsp;<span style="color:blue;">static</span>&nbsp;<span style="color:#2b91af;">Lazy</span>&lt;<span style="color:#2b91af;">Func</span>&lt;<span style="color:#2b91af;">T2</span>,&nbsp;<span style="color:#2b91af;">TResult</span>&gt;&gt;&nbsp;<span style="color:#74531f;">Apply</span>&lt;<span style="color:#2b91af;">T1</span>,&nbsp;<span style="color:#2b91af;">T2</span>,&nbsp;<span style="color:#2b91af;">TResult</span>&gt;(
488+
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">this</span>&nbsp;<span style="color:#2b91af;">Func</span>&lt;<span style="color:#2b91af;">T1</span>,&nbsp;<span style="color:#2b91af;">T2</span>,&nbsp;<span style="color:#2b91af;">TResult</span>&gt;&nbsp;<span style="font-weight:bold;color:#1f377f;">selector</span>,
489+
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#2b91af;">Lazy</span>&lt;<span style="color:#2b91af;">T1</span>&gt;&nbsp;<span style="font-weight:bold;color:#1f377f;">source</span>)
490+
{
491+
&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:#8f08c4;">return</span>&nbsp;<span style="color:blue;">new</span>&nbsp;<span style="color:#2b91af;">Lazy</span>&lt;<span style="color:#2b91af;">Func</span>&lt;<span style="color:#2b91af;">T2</span>,&nbsp;<span style="color:#2b91af;">TResult</span>&gt;&gt;(
492+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;()&nbsp;=&gt;&nbsp;<span style="font-weight:bold;color:#1f377f;">y</span>&nbsp;=&gt;&nbsp;<span style="font-weight:bold;color:#1f377f;">selector</span>(<span style="font-weight:bold;color:#1f377f;">source</span>.Value,&nbsp;<span style="font-weight:bold;color:#1f377f;">y</span>));
493+
}</pre>
494+
</p>
495+
<p>
496+
I keep learning during and after writing these articles, and it's possible that some of the connections you point out weren't entirely clear to me when I wrote. Or perhaps I was driven by a didactic motivation of presenting the concept in as clean a way as possible. Sometimes, I gloss over some details in order to get an overall point across. I honestly no longer remember exactly what motivated me to leave out that detail back then, but it was probably some combination of the above.
497+
</p>
498+
<p>
499+
You are correct that currying is the key to making this simpler. <a href="/2018/10/15/an-applicative-password-list#0ded7ac93aad8ba7b1063dd49c2051f1">Tyson Williams pointed this out to me in 2018</a>.
500+
</p>
501+
<p>
502+
FWIW, until recently I had a tendency to forget about <code>liftA2</code> and its cousins, so I developed a habit of writing Haskell expressions like <code>(+) &lt;$&gt; (Just 10) &lt;*&gt; (Just 32)</code>, as witnessed by, among others, <a href="/2022/01/17/enumerate-wordle-combinations-with-an-applicative-functor">this article</a>.
503+
</p>
504+
<p>
505+
Is your final C# example to be preferred? I'm not sure. I haven't tried to actually write it out, so perhaps I'm missing something, but as far as I can tell, it's an extension method on <code>Func</code> that takes a single 'applicative value' as an argument. If so, isn't it more or less the above <code>Apply</code> overload with a different name?
506+
</p>
507+
<p>
508+
As far as I can tell, that's not the idiomatic <code>Select</code> shape that most C# developers are used to, since it has its arguments swapped. You and I may realize that this is still isomorphic to the 'standard' <code>Select</code> signature, but I think that we've now moved beyond what most professional C# developers are willing to grapple with.
509+
</p>
510+
<p>
511+
I don't mean that as an attack on your comments. I think that you are correct. Rather, during and after writing this article series on applicative functors, I've come to appreciate that however useful that abstraction is, it's not a good fit in C#.
512+
</p>
513+
</div>
514+
<div class="comment-date">2025-03-04 08:04 UTC</div>
515+
</div>
479516
</div>

0 commit comments

Comments
 (0)