On Fri, 13 Feb 2009 11:09:35 +0100, Paolino <paolo.verone...@gmail.com> wrote:

When I came to haskell, I arrived with a small and only evolutionary
background in programming. First monad I met was MonadState StdGen m.
Everything was in someway acceptable, I had no problem in
explicitating the need for the generator.
The lesson was referential transparency. To me referential tranparency
is still obscure as a feature.
Not using the monad , my functions pass around a generator, then they
are repeatable, same generator , same computation.
Years pass by, now evolutionary algorithms need to scale multicores.
But multicore can be used with threads or par, the difference is that
par is pure, because it respects referential transparency. But threads
not.
They are always unrespectful ? Or it's an implementation issue of
preemptive choice?
Can I have a baton to pass around like I had for random generator, so
that the computation ends without IO (unsafe performed) , without
breaking tranparency,
something like (runIOThreads :: ThreadsIO a -> ThreadsBaton -> a) ?
From Real World Haskell my algorithm have to be parallelized as they
don't do some kind of IO, they don't deal with the world, but where is
it stated that it is possible  to write them with par (I couldn't) ?
More , I'm not caring  that my computation is unrepeatable, for me
it's fine that  the runtime system  gives me the cached results for
same arguments computation. The fact that it doesn't ,and recompute
the function giving out something fuzzily different from before, is
enough to coerce me to spit out IO  values ?
Finally, why and where the optimizer will substitute a value with its
definition, so that it possibly get computed twice ?

Thanks

paolino

I am not an expert in this matter, but as nobody answered sofar (perhaps people were frightened off by a lack of structure in your text), I will try to give some pointers:

 - You can start a function with parameters in a thread like this
     threadId <- forkIO (foo 42)
   where foo has type Int -> IO ()

 - Communication between threads can be done with MVars, see:
     
http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html

 - You can find concurrency demos at:
     http://www.haskell.org/haskellwiki/Concurrency_demos

 - Links to articles about parallelism:
     http://www.haskell.org/haskellwiki/Blog_articles/Parallel

 - To prevent recomputing, read:
     http://www.haskell.org/haskellwiki/Memoization

--
Regards,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to