Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Unmaybe (Adrian May)
   2.  Fish tank monad (Adrian May)
   3. Re:  Fish tank monad (Stephen Tetley)
   4. Re:  Fish tank monad (Ertugrul S?ylemez)


----------------------------------------------------------------------

Message: 1
Date: Fri, 17 May 2013 20:55:31 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Unmaybe
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAD-UbzH=qybb0h3-w8xnmao7rfou-hnwbmwwzpva-brrhgh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I don't suppose anybody really cares how this Gantt chart came out, but
just in case, I blogged about it:

http://nuerd.blogspot.tw/2013/05/gantt-chart-in-haskell.html

Adrian.



On 15 May 2013 23:19, Brent Yorgey <[email protected]> wrote:

> On Wed, May 15, 2013 at 10:37:56PM +0800, Adrian May wrote:
> >
> > I'd best give names to those forks though otherwise the whole project
> plan
> > will break whenever I insert a new one. Can I give a parameter to an
> > operator? Like:
> >
> > task1 `fork "name"` taskb
> >
> > task1 ( >^> "name" ) taskb
>
> No, unfortunately neither of those is possible.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130517/5a5b6d94/attachment-0001.htm>

------------------------------

Message: 2
Date: Sat, 18 May 2013 01:51:11 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Fish tank monad
To: "[email protected]" <[email protected]>
Message-ID:
        <cad-ubzfjf7g+du7s_-svuc2+jr2stftmo4zt0cjyjmyayui...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi folks,

I think I need a monad but I'm not sure which, and maybe something simpler
would do.

I want to model a fish tank as a function of time onto how many fish there
are in it at that time. If I already have such a function, I want to
operate on it with something like "add 2 fish on day 20" or "take 3 away on
day 15" to get a new function of the same form, but the latter should not
remove more fish than there are in the tank at that time, and it should
tell me how many I get. I don't promise to apply these operators in
chronological order.

This seems like the kind of thing that would be in the prelude somewhere.
But where?

TIA,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130518/33e25e5f/attachment-0001.htm>

------------------------------

Message: 3
Date: Sat, 18 May 2013 06:57:11 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Fish tank monad
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cab2tprabvucb26omspfupefd6zuj9jx2dagwoozu-89nmnf...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

>From the description, it sounds like you need an "evaluation
procedure" more than you need a monad (though a solution is likely to
use a state monad to track the number of fish in the tank).

How would you want to account for days? E.g. Do you want to run for a
month (dropping actions outside the time frame) or do you want to run
until the last action occurs?



------------------------------

Message: 4
Date: Sat, 18 May 2013 08:45:40 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] Fish tank monad
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Adrian May <[email protected]> wrote:

> I want to model a fish tank as a function of time onto how many fish
> there are in it at that time. If I already have such a function, I
> want to operate on it with something like "add 2 fish on day 20" or
> "take 3 away on day 15" to get a new function of the same form, but
> the latter should not remove more fish than there are in the tank at
> that time, and it should tell me how many I get. I don't promise to
> apply these operators in chronological order.
>
> This seems like the kind of thing that would be in the prelude
> somewhere. But where?

Let's see.  You want to model a "number of fish" value:

    Integer

but that value depends on time:

    Time -> Integer

So you have a "what do I get?" and a "how do I get it?".  The former can
be abstracted away:

    type Timed a = Time -> a
    type Timed a = (->) Time a
    type Timed = (->) Time

And yes, Timed is a monad.  You may know it as Reader Time, but Reader
is just (->) in disguise.  However, you don't need it to be a monad:

    applyAt :: Time -> (a -> a) -> Timed a -> Timed a
    applyAt tEv f c t
        | t >= tEv  = f (c t)
        | otherwise = c t

Then you can add two fish on day 20:

    applyAt 20 (+ 2)

and take 3 away on day 15:

    applyAt 15 (subtract 3)

Have fun. =)


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130518/e73a4c9a/attachment-0001.pgp>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 59, Issue 23
*****************************************

Reply via email to