<?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; continuous</title>
	<atom:link href="http://conal.net/blog/tag/continuous/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>Why program with continuous time?</title>
		<link>http://conal.net/blog/posts/why-program-with-continuous-time</link>
		<comments>http://conal.net/blog/posts/why-program-with-continuous-time#comments</comments>
		<pubDate>Sun, 03 Jan 2010 02:39:49 +0000</pubDate>
		<dc:creator><![CDATA[Conal]]></dc:creator>
				<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[continuous]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://conal.net/blog/?p=93</guid>
		<description><![CDATA[For me functional reactive programming (FRP) has been mainly about two principles. One is denotational design (i.e., based on simple, precise denotational semantics), which has been integral to FRP since the first incarnation as ActiveVRML. I&#8217;ve written several things recently about denotational design. My second core principle is continuous time, which has been present since [&#8230;]]]></description>
				<content:encoded><![CDATA[<!-- 

Title: Why program with continuous time?

Tags: design, continuous

URL: http://conal.net/blog/posts/why-program-with-continuous-time/

-->

<!-- references -->

<p>For me functional reactive programming (FRP) has been mainly about two principles.</p>

<p>One is <em>denotational design</em> (i.e., based on simple, precise denotational semantics), which has been integral to FRP since the first incarnation as <a href="http://conal.net/papers/ActiveVRML/" title="Paper">ActiveVRML</a>.
I&#8217;ve written <a href="http://conal.net/papers/push-pull-frp/" title="Paper">several</a> <a href="http://conal.net/blog/posts/beautiful-differentiation/" title="blog post">things</a> <a href="http://conal.net/blog/posts/denotational-design-with-type-class-morphisms/" title="blog post">recently</a> about denotational design.</p>

<p>My second core principle is <em>continuous time</em>, which has been present since <a href="http://conal.net/papers/icfp97/" title="Paper">Fran</a> &amp; ActiveVRML&#8217;s predecessor <a href="http://conal.net/papers/siggraph94.pdf" title="Paper">TBAG</a>.</p>

<p>Today I read a confusion that I&#8217;ve heard many times before about continuous time, which I&#8217;d like to bring up, in part because I love continuous time, and in part because there&#8217;s a much broader underlying principle of software design.</p>

<blockquote>
  <p>[&#8230;] I don&#8217;t see why the lack of continuous streams leaves a &#8220;gap&#8221;.  In the end all streams are discrete.</p>
</blockquote>

<p>&#8220;In the end&#8221;, yes.
Just as in the end, numbers are displayed as ascii numerals.
However, programming is more about the middle than the end, i.e., more about composition than about output.
For that reason, we don&#8217;t generally use strings in place of numbers.
If we did, composition operations (arithmetic) would be very awkward.
Similarly, continuity in space and in time is better for composition/modularity, leaving discreteness to the output step.</p>

<p>Another name for &#8220;continuous&#8221; is &#8220;resolution-independent&#8221;, and thus able to be transformed in time and space with ease and without propagating and amplifying sampling artifacts.</p>

<p>As another example, consider the data types in a 3D graphics API.
In the end, all graphics is pixels, isn&#8217;t it?
So what gap is left in a pixel-oriented API that doesn&#8217;t address higher-level continuous notions like triangles or curved surfaces?
(Hint: it&#8217;s not just speed.)</p>

<p>One could go further than strings and pixels, and say that &#8220;in the end&#8221; my data types will end up as phosphors or electrical impulses, so programming at those levels is perfectly adequate.
Again, composability would suffer.</p>

<p>Another example is functional vs imperative programming.
It&#8217;s all side-effects <em>in the end</em>.
Functional programming excels in composability, as explained and illustrated by John Hughes in <em><a href="http://www.cse.chalmers.se/~rjmh/Papers/whyfp.html" title="Paper by John Hughes">Why Functional Programming Matters</a></em>.
And I&#8217;m not just talking about <em>pure</em> functional programming, but the availability of compound <em>expressions</em>, as introduced in Fortran (controversially), despite that machines just execute sequences of atomic, side-effecting statements <em>in the end</em>.</p>

<p>Another example, and really the heart of John&#8217;s paper, is finite vs infinite data structures.
We only access a finite amount of data <em>in the end</em>.
However, allowing infinite data structures <em>in the middle</em> makes for a much more composable programming style.</p>

<p>Some unsolicited advice to us all: Next time you see someone doing something and you don&#8217;t understand their underlying motivation, ask them.
Many issues are not immediately obvious, so don&#8217;t be shy!
Reading papers can help as well.</p>

<p>For more on continuous time:</p>

<ul>
<li><em><a href="http://conal.net/papers/siggraph94.pdf" title="Paper">TBAG: A High Level Framework for Interactive, Animated 3D Graphics Applications</a></em></li>
<li><em><a href="http://conal.net/papers/icfp97/" title="Paper">Functional Reactive Animation</a></em></li>
<li><em><a href="http://conal.net/papers/tse-modeled-animation/" title="Paper">An Embedded Modeling Language Approach to Interactive 3D and Multimedia Animation</a></em></li>
<li><em><a href="http://conal.net/papers/plilpalp98/" title="Paper">Functional Implementations of Continuous Modeled Animation</a></em></li>
</ul>

<p><strong>Edits</strong>:</p>

<ul>
<li>2010-01-03: Trimmed &amp; tweaked the unsolicited advice.  Hopefully less peevish/patronizing now.  Thanks for the feedback.</li>
<li>2010-01-07: Trimmed quote.</li>
</ul>
<p><a href="http://conal.net/blog/?flattrss_redirect&amp;id=93&amp;md5=f0b90f75493a7528a9ffe8114d2781c5"><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/why-program-with-continuous-time/feed</wfw:commentRss>
		<slash:comments>16</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%2Fwhy-program-with-continuous-time&amp;language=en_GB&amp;category=text&amp;title=Why+program+with+continuous+time%3F&amp;description=For+me+functional+reactive+programming+%28FRP%29+has+been+mainly+about+two+principles.+One+is+denotational+design+%28i.e.%2C+based+on+simple%2C+precise+denotational+semantics%29%2C+which+has+been+integral+to+FRP+since...&amp;tags=continuous%2Cdesign%2Cblog" type="text/html" />
	</item>
		<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>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><![CDATA[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[This post continues from &#8220;Reactive values from the future&#8221; and &#8220;Reactive normal form&#8221;. Fran/FRP reactive behaviors could change continuously, while reactive values change only discretely. The Reactive library keeps continuity orthogonal to reactivity. To combine continuity and reactivity, simply compose reactivity with a non-reactive type of functions of time. One could literally use Reactive (Time [&#8230;]]]></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>

<pre><code>data Fun t a = K a | Fun (t -&gt; a)
</code></pre>

<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>

<pre><code>instance Functor (Fun t) where
  fmap f (K   a) = K   (f a)
  fmap f (Fun g) = Fun (f.g)
</code></pre>

<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>

<pre><code>type Time = Double

type ReactiveB = Reactive :. Fun Time
</code></pre>

<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>
<p><a href="http://conal.net/blog/?flattrss_redirect&amp;id=11&amp;md5=dad114db31a6501c908baa7892572653"><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/blending-continuity-into-reactive-values/feed</wfw:commentRss>
		<slash:comments>7</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%2Fblending-continuity-into-reactive-values&amp;language=en_GB&amp;category=text&amp;title=Blending+continuity+into+reactive+values&amp;description=This+post+continues+from+%26%238220%3BReactive+values+from+the+future%26%238221%3B+and+%26%238220%3BReactive+normal+form%26%238221%3B.+Fran%2FFRP+reactive+behaviors+could+change+continuously%2C+while+reactive+values+change+only+discretely.+The+Reactive+library+keeps+continuity...&amp;tags=continuous%2Cdiscrete%2Coptimization%2Creactive+behavior%2Creactivity%2Ctime%2Ctype+composition%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>
