[Haskell-cafe] Bracket around every IO computation monad
Felipe Almeida Lessa
felipe.lessa at gmail.com
Sun Nov 7 19:50:23 EST 2010
(I won't answer your main question, I'll just write some notes on your
current code.)
On Sun, Nov 7, 2010 at 10:40 PM, Mitar <mmitar at gmail.com> wrote:
> neurons <- growNeurons [
> do { a <- attach nerve1; return $ Growable a },
> do { a <- attach nerve2; return $ Growable a },
> do { a <- attach nerve3; return $ Growable a }
> ]
Note that this is the same as
neuros <- growNeurons [
Growable <$> attach nerve1,
Growable <$> attach nerve2,
Growable <$> attach nerve3]
> Types of attach and deattach are (if I simplify):
>
> attach :: Nerve n -> IO (LiveNeuron n)
> deattach :: LiveNeuron n -> IO ()
>
> Growable is only used so that I can put actions of different type in the list.
Well, you could use
attachG :: Nerve n -> IO Growable
attachG n = Growable <$> attach n
...
neurons <- growNeurons [attachG nerve1, attachG nerve2, attachG nerve3]
Cheers,
--
Felipe.
More information about the Haskell-Cafe
mailing list