[Haskell-cafe] style question: Writer monad or unsafeIOToST?

Bulat Ziganshin bulat.ziganshin at gmail.com
Fri Aug 25 03:36:02 EDT 2006


Hello Gregory,

Friday, August 25, 2006, 3:08:09 AM, you wrote:

> Some performance data:  using unsafeIOToST to write log messages
> directly to the output, the simulation does 10^7 state updates in  
> about 45 seconds
> on my 1.5 GHz ppc G4.  Using LogT, with a list of strings as the monoid,
> it takes about 7 minutes to do the same, and the system swaps heavily
> during the last few minutes.  Not surprising, given that the mappend
> operation is not very efficient for the list monoid.

are you sure that you know how monads are implemented? IO/ST monads
just organize order of execution, without any penalty comparing
to imperative languages. but other monads and all monad transformers
add their data to the tuple passed between monad operations. and this
makes their execution significantly slower. you can read more about this
in http://sigfpe.blogspot.com/2006/08/you-could-have-invented-monads-and.html

about multi-threading - you can (and should!) use ghc's internal
concurrency with forkIO. it is a perfect way - with minimal overhead
and ability to use any Haskell features in each thread without
fighting against multi-threading implementation

-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list