<span class="Apple-style-span" style>&gt; x = constant 3 ^+^ time</span><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">If I understand the rest of your mail, Wire defines an Applicative instance, so why not:</font></div>

<div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">x = (+3) &lt;$&gt; time</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br>

</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">??<br></font><br><div class="gmail_quote">2011/12/12 Ertugrul Söylemez <span dir="ltr">&lt;<a href="mailto:es@ertes.de">es@ertes.de</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello fellows,<br>
<br>
after a few discussions on IRC and via private mail I feel obligated to<br>
point out that arrows and in particular AFRP do not force you to use an<br>
imperative style in any way.  You can use a style very similar to SHE&#39;s<br>
idiom brackets.  I will demonstrate this using the Netwire library.  The<br>
following code has a very imperative feel to it and also looks quite<br>
ugly:<br>
<br>
    myWire =<br>
        proc _ -&gt; do<br>
            fps &lt;- avgFpsInt 1000 100 -&lt; ()<br>
            t &lt;- time -&lt; ()<br>
            let x = 3 + t<br>
            y &lt;- integral 0 -&lt; t<br>
            returnA -&lt; printf &quot;%8.2f %8.2f %8.2f&quot; fps x y<br>
<br>
Let&#39;s improve this code.  The magic lies in identifying behaviors from<br>
classic FRP.  The arrow variables from the above code can be seen as the<br>
behaviors, but that&#39;s not very useful for getting rid of the imperative<br>
style.  A better way to look at it is that every wire that ignores its<br>
input (i.e. has a fully polymorphic input type) is a behavior, so let&#39;s<br>
find them.<br>
<br>
First of all it is impossible to write a proper Num instance for wires.<br>
The underlying problem is the same as for writing a Num instance for<br>
functions.  However, the Wire type forms a vector space, and the next<br>
release of Netwire will include the corresponding instances (see the<br>
vector-space package by Conal Elliot).  With them we can write:<br>
<br>
    x = constant 3 ^+^ time<br>
<br>
The x wire is our first behavior.  Passing x to a generic wire is<br>
simply regular arrow composition, giving you behaviors as functions of<br>
other behaviors, hence:<br>
<br>
    y = integral 0 &lt;&lt;&lt; x<br>
<br>
Also fps is just a simple behavior:<br>
<br>
    fps = avgFpsInt 1000 100<br>
<br>
To get to the final output there are multiple ways.  Perhaps the nicest<br>
way is to exploit the Applicative instance, giving you:<br>
<br>
    myWire =<br>
        liftA3 (printf &quot;%8.2f %8.2f %8.2f&quot;) fps x y<br>
<br>
        where<br>
        fps = avgFpsInt 1000 100<br>
        x   = constant 3 ^+^ time<br>
        y   = integral 0 &lt;&lt;&lt; x<br>
<br>
Looks much more declarative, no?  For more complicated compositions or<br>
generic wires use banana brackets or the combinator syntax in arrow<br>
notation.  Examples:<br>
<br>
    myWire = proc x -&gt;<br>
        (someWire -&lt; x) ^+^ (otherWire -&lt; 15)<br>
<br>
    myWire = proc x -&gt;<br>
        (| f (someWire -&lt; x) (otherWire -&lt; 15) |)<br>
<br>
This closely resembles idiom bracket notation, but allows you to be<br>
explicit about inputs, takes care of creating side channels and gives<br>
you the full power of arrows, including ArrowChoice and ArrowLoop.<br>
<br>
<br>
Greets,<br>
Ertugrul<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
nightmare = unsafePerformIO (getWrongWife &gt;&gt;= sex)<br>
<a href="http://ertes.de/" target="_blank">http://ertes.de/</a><br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>