I want to model a biological system in Haskell. I am thinking of doing it as following.
- Each cell is an entity; like an object in Object Oriented Programming. This entity can read global variables and update them. Each entity can have more than one function. Each function compute something when some global variables attain certain values. Depending on computation result, each function then update some global variable. Something like hardware description language like VHDL, Bluespec and Verilog.
What is the recommended way of doing it in Haskell. I know basic Haskell quite well. I am also comfortable with Monad and Arrows. I could grasp much when I read reactive banana library.
The thing you describe seems to be the actors model. This is bread and butter of Erlang programming language, but Haskell does not have actors primitives built-in. Quick Cabal inspection gives hactors
and simple-actors
, but I can't elaborate on details.
If you want an actor system in Haskell, I'd strongly suggest looking at Cloud Haskell. It is based on Erlang/OTP (offering the same message passing concurrency semantics and failure handling).
Caveats though: I am the maintainer. ;)
https://github.com/haskell-distributed http://haskell-distributed.github.io
Everybody else here has mentioned actors, so I wanted to chime in and mention pipes-concurrency
, which is a non-distributed form of actors.
Like actors, you have a way to spawn
a mailbox:
import Pipes
import Pipes.Concurrent
import qualified Pipes.Prelude
main = do
(output, input) <- spawn Unbounded
...
... send messages to mailboxes:
forkIO $ runEffect $ Pipes.Prelude.stdinLn >-> toOutput output
... and read messages off of mailboxes:
runEffect $ runEffect $ fromInput input >-> Pipes.Prelude.stdoutLn
You don't even have to use the pipes
interface. You can send individual messages at a time using send
:
send :: Output a -> a -> STM Bool
... and receive individual messages using recv
:
recv :: Input a -> STM (Maybe a)
It comes with an extended tutorial explaining how to use the library.
I want to model a biological system in Haskell. I am thinking of doing it as following.
- Each cell is an entity; like an object in Object Oriented Programming. This entity can read global variables and update them. Each entity can have more than one function. Each function compute something when some global variables attain certain values. Depending on computation result, each function then update some global variable. Something like hardware description language like VHDL, Bluespec and Verilog.
What is the recommended way of doing it in Haskell. I know basic Haskell quite well. I am also comfortable with Monad and Arrows. I could grasp much when I read reactive banana library.
The thing you describe seems to be the actors model. This is bread and butter of Erlang programming language, but Haskell does not have actors primitives built-in. Quick Cabal inspection gives hactors
and simple-actors
, but I can't elaborate on details.
If you want an actor system in Haskell, I'd strongly suggest looking at Cloud Haskell. It is based on Erlang/OTP (offering the same message passing concurrency semantics and failure handling).
Caveats though: I am the maintainer. ;)
https://github.com/haskell-distributed http://haskell-distributed.github.io
Everybody else here has mentioned actors, so I wanted to chime in and mention pipes-concurrency
, which is a non-distributed form of actors.
Like actors, you have a way to spawn
a mailbox:
import Pipes
import Pipes.Concurrent
import qualified Pipes.Prelude
main = do
(output, input) <- spawn Unbounded
...
... send messages to mailboxes:
forkIO $ runEffect $ Pipes.Prelude.stdinLn >-> toOutput output
... and read messages off of mailboxes:
runEffect $ runEffect $ fromInput input >-> Pipes.Prelude.stdoutLn
You don't even have to use the pipes
interface. You can send individual messages at a time using send
:
send :: Output a -> a -> STM Bool
... and receive individual messages using recv
:
recv :: Input a -> STM (Maybe a)
It comes with an extended tutorial explaining how to use the library.
0 commentaires:
Enregistrer un commentaire