<?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; discrete</title>
	<atom:link href="http://conal.net/blog/tag/discrete/feed/" rel="self" type="application/rss+xml" />
	<link>http://conal.net/blog</link>
	<description>Inspirations &#38; experiments, mainly about denotational programming in Haskell</description>
	<lastBuildDate>Fri, 30 Jul 2010 02:56:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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>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[]]></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 -->
]]></content:encoded>
			<wfw:commentRss>http://conal.net/blog/posts/simply-efficient-functional-reactivity/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Blending continuity into reactive values</title>
		<link>http://conal.net/blog/posts/blending-continuity-into-reactive-values/</link>
		<comments>http://conal.net/blog/posts/blending-continuity-into-reactive-values/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 23:13:46 +0000</pubDate>
		<dc:creator>conal</dc:creator>
				<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[continuous]]></category>
		<category><![CDATA[discrete]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[reactive behavior]]></category>
		<category><![CDATA[reactivity]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[type composition]]></category>

		<guid isPermaLink="false">http://conal.net/blog/posts/blending-continuity-into-reactive-values/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<!-- 

Title: Blending continuity into reactive values

Tags: reactivity, discrete, continuous, reactive behaviors, optimization, type composition, time

-->

<!-- references -->

<!-- teaser -->

<p>This post continues from <a href="http://conal.net/blog/posts/reactive-values-from-the-future/" title="Blog post: &quot;Reactive values from the future&quot;">&#8220;Reactive values from the future&#8221;</a> and <a href="http://conal.net/blog/posts/reactive-normal-form/" title="Blog post: &quot;Reactive normal form&quot;">&#8220;Reactive normal form&#8221;</a>.</p>

<p>Fran/FRP reactive behaviors could change <em>continuously</em>, while reactive values change only <em>discretely</em>.  The <a href="http://haskell.org/haskellwiki/Reactive" title="Wiki page for the Reactive library">Reactive</a> library keeps continuity orthogonal to reactivity.  To combine continuity and reactivity, simply compose reactivity with a non-reactive type of functions of time.</p>

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

<p>One could literally use <code>Reactive (Time -&gt; a)</code>, but Reactive also includes a more optimizable version as the module <a href="http://darcs.haskell.org/packages/reactive/doc/html/Data-Fun.html" title="Documentation for module Data.Fun in the Reactive library"><code>Data.Fun</code></a>.  The denotation of <code>Fun t a</code> is simply <code>t -&gt; a</code>, but it has a constructor (<code>K</code>) for constant-valued functions, which occur frequently.</p>

<p><div>
<pre class="haskell"><span style="color: #050; font-weight: bold;">data</span> Fun t a = K a | Fun <span style="color: green;">&#40;</span>t -&gt; a<span style="color: green;">&#41;</span></pre>
</div></p>

<p>As with the other types in Reactive, most of the operations on <code>Fun</code> values are in the form of instances of standard type classes, specifically <code>Monoid</code>, <code>Functor</code>, <code>Applicative</code>, <code>Monad</code>, and <code>Arrow</code>.  As an example of optimization,</p>

<p><div>
<pre class="haskell"><span style="color: #050; font-weight: bold;">instance</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Functor"><span style="color: #833; font-weight: bold;">Functor</span></a> <span style="color: green;">&#40;</span>Fun t<span style="color: green;">&#41;</span> <span style="color: #050; font-weight: bold;">where</span>
  <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap"><span style="font-weight: bold;">fmap</span></a> f <span style="color: green;">&#40;</span>K   a<span style="color: green;">&#41;</span> = K   <span style="color: green;">&#40;</span>f a<span style="color: green;">&#41;</span>
  <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:fmap"><span style="font-weight: bold;">fmap</span></a> f <span style="color: green;">&#40;</span>Fun g<span style="color: green;">&#41;</span> = Fun <span style="color: green;">&#40;</span>f.g<span style="color: green;">&#41;</span></pre>
</div></p>

<p><code>Data.Reactive</code> defines reactive behaviors very simply as a <a href="http://haskell.org/haskellwiki/TypeCompose" title="Wiki page for the TypeCompose library">type composition</a> of <code>Reactive</code> and <code>Fun Time</code>:</p>

<p><div>
<pre class="haskell"><span style="color: #050; font-weight: bold;">type</span> Time = <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Double"><span style="color: #833; font-weight: bold;">Double</span></a>
&nbsp;
<span style="color: #050; font-weight: bold;">type</span> ReactiveB = Reactive :. Fun Time</pre>
</div></p>

<p>Wrapping the combination in a <a href="http://haskell.org/haskellwiki/TypeCompose" title="Wiki page for the TypeCompose library">type composition</a> (<code>g :. f</code>) gives <code>Functor</code> and <code>Applicative</code> instances for reactive behaviors that combine the corresponding instances for <code>Reactive</code> and <code>Fun Time</code>.</p>

<p>Combining reactive values and non-reactive functions in this way, we can create implementations that mix data-driven (push) and demand-driven (pull) evaluation.  The reactive value part is data-driven, resulting in a time function.  That time function can then be polled until a new time function is pushed for further polling.  As an important optimization, only poll when the time function is really time-varying (made with the <code>Fun</code> constructor).  If it&#8217;s constant (made with <code>K</code>), then output the value just once and wait until the next push.</p>

<p>I&#8217;m not sure whether this elegant composition of orthogonal notions is really a good idea in practice.  A benefit is the extra static typing and ability to use of the two types independently.  A drawback is that the operations on reactive values have to be rewrapped and perhaps tweaked for convenient use directly on reactive behaviors.</p>
]]></content:encoded>
			<wfw:commentRss>http://conal.net/blog/posts/blending-continuity-into-reactive-values/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
