<p dir="ltr">Thanks! In the mean time I figured out that I need something completely different though. Actually, they&#39;re not fish, they&#39;re assorted programmers, and I need to approach the hiring plan with tasks (as in the Gantt chart code at <a href="http://nuerd.blogspot.com">http://nuerd.blogspot.com</a>) calling for certain skills and get a possibly non-contiguous booking. A Timed Integer won&#39;t support that though, unless I step through it day by day which would seem needlessly goofy. It&#39;s at brainstorming stage right now but I think I can probably plough through it, then I&#39;ll probably be back asking for help with boilerplate reduction.</p>

<p dir="ltr">Adrian.<br>
</p>
<div class="gmail_quote">On 18 May 2013 14:48, &quot;Ertugrul Söylemez&quot; &lt;<a href="mailto:es@ertes.de">es@ertes.de</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Adrian May &lt;<a href="mailto:adrian.alexander.may@gmail.com">adrian.alexander.may@gmail.com</a>&gt; wrote:<br>
<br>
&gt; I want to model a fish tank as a function of time onto how many fish<br>
&gt; there are in it at that time. If I already have such a function, I<br>
&gt; want to operate on it with something like &quot;add 2 fish on day 20&quot; or<br>
&gt; &quot;take 3 away on day 15&quot; to get a new function of the same form, but<br>
&gt; the latter should not remove more fish than there are in the tank at<br>
&gt; that time, and it should tell me how many I get. I don&#39;t promise to<br>
&gt; apply these operators in chronological order.<br>
&gt;<br>
&gt; This seems like the kind of thing that would be in the prelude<br>
&gt; somewhere. But where?<br>
<br>
Let&#39;s see.  You want to model a &quot;number of fish&quot; value:<br>
<br>
    Integer<br>
<br>
but that value depends on time:<br>
<br>
    Time -&gt; Integer<br>
<br>
So you have a &quot;what do I get?&quot; and a &quot;how do I get it?&quot;.  The former can<br>
be abstracted away:<br>
<br>
    type Timed a = Time -&gt; a<br>
    type Timed a = (-&gt;) Time a<br>
    type Timed = (-&gt;) Time<br>
<br>
And yes, Timed is a monad.  You may know it as Reader Time, but Reader<br>
is just (-&gt;) in disguise.  However, you don&#39;t need it to be a monad:<br>
<br>
    applyAt :: Time -&gt; (a -&gt; a) -&gt; Timed a -&gt; Timed a<br>
    applyAt tEv f c t<br>
        | t &gt;= tEv  = f (c t)<br>
        | otherwise = c t<br>
<br>
Then you can add two fish on day 20:<br>
<br>
    applyAt 20 (+ 2)<br>
<br>
and take 3 away on day 15:<br>
<br>
    applyAt 15 (subtract 3)<br>
<br>
Have fun. =)<br>
<br>
<br>
Greets,<br>
Ertugrul<br>
<br>
--<br>
Not to be or to be and (not to be or to be and (not to be or to be and<br>
(not to be or to be and ... that is the list monad.<br>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div>