[Haskell-cafe] Bracket around every IO computation monad

Mitar mmitar at gmail.com
Tue Nov 16 09:57:15 EST 2010


Hi!

On Tue, Nov 16, 2010 at 2:05 AM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> The assumption being that Mitar's Nerves are scarce resources (like
> files for example). Meaning:

Yes. My nerves are really a scarce resource. ;-) And I haven't yet
heard anybody comparing them to files. I heard that they are short and
sometimes people step on some of them. But not that they are like
files. ;-) I have to tell this to my fellow neuroscientists. This is a
whole new paradigm. ;-)

But yes, Nerves were modeled by looking at file handles. And were also
made so that they fit nicely into the "bracket" function. They are
mostly a wrapper around scarce resource (like display, complex
computation (CPU), sensors and similar). This is why there has to be
some preparation and cleanup.

In fact your approach opens a whole new idea for me. Because currently
my whole main program was:

attach everything together, if error while attaching cleanup and exit
wait until everything lives/works or until an error
cleanup everything and wait until everything is really cleaned up
exit

The whole main program just prepares my generic data-flow computation
framework I am developing. So that attaching is how all flows (called
Nerves) are interconnected and then you let it live and process.

So your approach is interesting because I could do cleanup at one
place, and it wouldn't matter if I am doing this in the "attach" phase
(which this thread is about) or any other phase.

> someOperation :: LiveNeuron n -> IO ()
>
> (I'm not sure Mitar actually has this...)

No. In fact Neurons are defined with an operation they do. You just
feed them with data and they output data. In main program you do not
do operations over them. You just grow/prepare them and
attache/interconnect them.

> 4) It's important not to leave handles open (or in this case leave
> nerves attached) when they don't need to be. In the case of files when
> you leave a file open when you're not using it anymore, other
> processes may not be able to use the file.
>
> (I'm not sure this is a requirement for Nerves...)

It is. Because they encapsulate also complex resources like sensors,
cameras, displays, keyboard and similar things. (But they can also be
quite low-level too.)

> (Again, I'm not sure a similar requirement exists for LiveNeurons)

It does. Once things are cleaned up there should be no other use of them.


Mitar


More information about the Haskell-Cafe mailing list