<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Conal Elliott &#187; joinMaybes</title>
	<atom:link href="http://conal.net/blog/tag/joinmaybes/feed" rel="self" type="application/rss+xml" />
	<link>http://conal.net/blog</link>
	<description>Inspirations &#38; experiments, mainly about denotative/functional programming in Haskell</description>
	<lastBuildDate>Thu, 25 Jul 2019 18:15:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.17</generator>
	<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=conal&amp;popout=1&amp;url=http%3A%2F%2Fconal.net%2Fblog%2F&amp;language=en_US&amp;category=text&amp;title=Conal+Elliott&amp;description=Inspirations+%26amp%3B+experiments%2C+mainly+about+denotative%2Ffunctional+programming+in+Haskell&amp;tags=blog" type="text/html" />
	<item>
		<title>Simply efficient functional reactivity</title>
		<link>http://conal.net/blog/posts/simply-efficient-functional-reactivity</link>
		<comments>http://conal.net/blog/posts/simply-efficient-functional-reactivity#comments</comments>
		<pubDate>Fri, 04 Apr 2008 22:27:43 +0000</pubDate>
		<dc:creator><![CDATA[Conal]]></dc:creator>
				<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[applicative functor]]></category>
		<category><![CDATA[continuous]]></category>
		<category><![CDATA[discrete]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[functional reactive programming]]></category>
		<category><![CDATA[functor]]></category>
		<category><![CDATA[future value]]></category>
		<category><![CDATA[icfp]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[joinMaybes]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[monoid]]></category>
		<category><![CDATA[multi-threading]]></category>
		<category><![CDATA[normal form]]></category>
		<category><![CDATA[paper]]></category>
		<category><![CDATA[reactive behavior]]></category>
		<category><![CDATA[reactive value]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[type class]]></category>
		<category><![CDATA[type class morphism]]></category>
		<category><![CDATA[type composition]]></category>

		<guid isPermaLink="false">http://conal.net/blog/posts/simply-efficient-functional-reactivity/</guid>
		<description><![CDATA[I submitted a paper Simply efficient functional reactivity to ICFP 2008. Abstract: Functional reactive programming (FRP) has simple and powerful semantics, but has resisted efficient implementation. In particular, most past implementations have used demand-driven sampling, which accommodates FRP&#8217;s continuous time semantics and fits well with the nature of functional programming. Consequently, values are wastefully recomputed [&#8230;]]]></description>
				<content:encoded><![CDATA[<!-- 

Title: Simply efficient functional reactivity

Tags: applicative functor, continuous, discrete, event, FRP, functional reactive programming, functor, future value, icfp, implementation, joinMaybes, monad, monoid, type class morphism, multi-threading, normal form, paper, reactive behavior, reactive value, semantics, time, type class, type composition

URL: http://conal.net/blog/posts/simply-efficient-functional-reactivity/

-->

<!-- references -->

<!-- teaser -->

<p>I submitted a paper <em><a href="http://conal.net/papers/simply-reactive" title="Paper: &quot;Simply efficient functional reactivity&quot;">Simply efficient functional reactivity</a></em> to <a href="http://www.icfpconference.org/icfp2008" title="ICFP 2008 conference page">ICFP 2008</a>.</p>

<p><strong>Abstract:</strong></p>

<blockquote>
  <p>Functional reactive programming (FRP) has simple and powerful semantics, but has resisted efficient implementation.  In particular, most past implementations have used demand-driven sampling, which accommodates FRP&#8217;s continuous time semantics and fits well with the nature of functional programming.  Consequently, values are wastefully recomputed even when inputs don&#8217;t change, and reaction latency can be as high as the sampling period.</p>
  
  <p>This paper presents a way to implement FRP that combines data- and demand-driven evaluation, in which values are recomputed only when necessary, and reactions are nearly instantaneous.  The implementation is rooted in a new simple formulation of FRP and its semantics and so is easy to understand and reason about.</p>
  
  <p>On the road to efficiency and simplicity, we&#8217;ll meet some old friends (monoids, functors, applicative functors, monads, morphisms, and improving values) and make some new friends (functional future values, reactive normal form, and concurrent &#8220;unambiguous choice&#8221;).</p>
</blockquote>

<!--
**Edits**:

* 2008-02-09: just fiddling around
-->

<!-- without a comment or something here, the last item above becomes a paragraph -->
<p><a href="http://conal.net/blog/?flattrss_redirect&amp;id=22&amp;md5=dee648d38383131c59963d5b9b4c4b93"><img src="http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png" srcset="http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png, http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white@2x.png 2xhttp://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png, http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white@3x.png 3x" alt="Flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conal.net/blog/posts/simply-efficient-functional-reactivity/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=conal&amp;popout=1&amp;url=http%3A%2F%2Fconal.net%2Fblog%2Fposts%2Fsimply-efficient-functional-reactivity&amp;language=en_GB&amp;category=text&amp;title=Simply+efficient+functional+reactivity&amp;description=I+submitted+a+paper+Simply+efficient+functional+reactivity+to+ICFP+2008.+Abstract%3A+Functional+reactive+programming+%28FRP%29+has+simple+and+powerful+semantics%2C+but+has+resisted+efficient+implementation.+In+particular%2C+most+past...&amp;tags=applicative+functor%2Ccontinuous%2Cdiscrete%2Cevents%2CFRP%2Cfunctional+reactive+programming%2Cfunctor%2Cfuture+value%2Cicfp%2Cimplementation%2CjoinMaybes%2Cmonad%2Cmonoid%2Cmulti-threading%2Cnormal+form%2Cpaper%2Creactive+behavior%2Creactive+value%2Csemantics%2Ctime%2Ctype+class%2Ctype+class+morphism%2Ctype+composition%2Cblog" type="text/html" />
	</item>
		<item>
		<title>A handy generalized filter</title>
		<link>http://conal.net/blog/posts/a-handy-generalized-filter</link>
		<comments>http://conal.net/blog/posts/a-handy-generalized-filter#comments</comments>
		<pubDate>Sat, 26 Jan 2008 02:52:42 +0000</pubDate>
		<dc:creator><![CDATA[Conal]]></dc:creator>
				<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[joinMaybes]]></category>
		<category><![CDATA[monad]]></category>

		<guid isPermaLink="false">http://conal.net/blog/posts/a-handy-generalized-filter/</guid>
		<description><![CDATA[For quite a while, I&#8217;ve been using a handy operation for filtering functional events: justE :: Event (Maybe a) -&#62; Event a The idea of justE is to drop the Nothing-valued occurrences and strip off the Just constructors from the remaining occurrences. Recently I finally noticed the similarity with a standard function (in Data.Maybe): catMaybes [&#8230;]]]></description>
				<content:encoded><![CDATA[<!-- 

Title: A handy generalized filter

Tags: joinMaybes, monads, events, filter

-->

<!-- references -->

<!-- teaser -->

<p>For quite a while, I&#8217;ve been using a handy operation for filtering functional events:</p>

<pre><code>justE :: Event (Maybe a) -&gt; Event a
</code></pre>

<p>The idea of <code>justE</code> is to drop the <code>Nothing</code>-valued occurrences and strip off the <code>Just</code> constructors from the remaining occurrences.  Recently I finally noticed the similarity with a standard function (in <code>Data.Maybe</code>):</p>

<pre><code>catMaybes :: [Maybe a] -&gt; [a]
</code></pre>

<p><span id="more-12"></span></p>

<p>I <a href="http://tunes.org/~nef/logs/haskell/07.12.26" title="IRC log: #haskell, December 26 2007">asked on #haskell</a> about a common generalization, and oerjan offered the following:</p>

<pre><code>joinMaybes :: MonadPlus m =&gt; m (Maybe a) -&gt; m a
joinMaybes = (&gt;&gt;= maybe mzero return)
</code></pre>

<p>I like this name and definition very much, including the use of <code>mzero</code> and <code>return</code> for empty and singleton monadic values, respectively.  I particularly like how it works out for lists and events.  Each element is passed into <code>maybe mzero return</code>, so that a <code>Nothing</code> becomes empty (<code>mzero</code>), while a <code>Just x</code> becomes a singleton (<code>return x</code>).</p>

<p>I also like how <code>joinMaybes</code> specializes easily into traditional, predicate-based filtering, generalizing the standard <code>filter</code> function on lists:</p>

<pre><code>filterMP :: MonadPlus m =&gt; (a -&gt; Bool) -&gt; m a -&gt; m a
filterMP p m = joinMaybes (liftM f m)
 where
   f a | p a       = Just a
       | otherwise = Nothing
</code></pre>

<p>So it&#8217;s easy to define <code>filterMP</code> in terms of <code>joinMaybes</code> (and hence <code>filter</code> in terms of <code>catMaybes</code>).  What about the reverse?  Here&#8217;s one go at it:</p>

<pre><code>filterMP' :: MonadPlus m =&gt; (a -&gt; Bool) -&gt; m a -&gt; m a
filterMP' p = (&gt;&gt;= f)
 where
   f a | p a       = return a
       | otherwise = mzero

joinMaybes' :: MonadPlus m =&gt; m (Maybe a) -&gt; m a
joinMaybes' = liftM fromJust . filterMP' isJust
</code></pre>

<p>Comparable simplicity, but I don&#8217;t like the <code>isJust</code> and <code>fromJust</code>.  Not only is there some redundant checking, but the <code>fromJust</code> function is partial, and so this definition is not so obviously total to an automated checker like <a href="http://www-users.cs.york.ac.uk/~ndm/catch/" title="Project page: &quot;Catch: Case Totality Checker for Haskell&quot;">Catch</a>.</p>

<hr />

<p><em>Edit 2008-02-08</em>: added a &#8220;Continue reading &#8230;&#8221; token, to keep my blog&#8217;s front page uncluttered.</p>
<p><a href="http://conal.net/blog/?flattrss_redirect&amp;id=12&amp;md5=380e46a02c42296b7d57cd6b5619b167"><img src="http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png" srcset="http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png, http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white@2x.png 2xhttp://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png, http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white@3x.png 3x" alt="Flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conal.net/blog/posts/a-handy-generalized-filter/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=conal&amp;popout=1&amp;url=http%3A%2F%2Fconal.net%2Fblog%2Fposts%2Fa-handy-generalized-filter&amp;language=en_GB&amp;category=text&amp;title=A+handy+generalized+filter&amp;description=For+quite+a+while%2C+I%26%238217%3Bve+been+using+a+handy+operation+for+filtering+functional+events%3A+justE+%3A%3A+Event+%28Maybe+a%29+-%26gt%3B+Event+a+The+idea+of+justE+is+to+drop+the...&amp;tags=events%2Cfilter%2CjoinMaybes%2Cmonad%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>
