Proposal: add forkOnIO and friends to Control.Concurrent:

Maciej Piechotka uzytkownik2 at gmail.com
Sun Jan 2 02:35:56 CET 2011


On Sat, 2011-01-01 at 13:59 -0500, Brandon S Allbery KF8NH wrote:
> On 12/23/10 20:57 , Thomas Schilling wrote:
> > I also find the name 'forkOnIO' extremely confusing.  Without reading
> > the docs it seems to imply that a thread is created on IO, i.e., if
> > I/O happens.  This makes no sense, and is of course not what's
> > happening.  However, I assume you chose it because forkIOOn looks a
> > bit weird.  In that case, why not use forkThreadOn, and in a separate
> > proposal change forkIO to forkThread (or just fork).
> 
> +1
> The name "forkIO" always seemed a bit odd to me; aren't threads pretty much
> constrained to IO anyway?
> 

Depends on what you understand by thread:

> import Control.DeepSeq
> import Control.Parallel
> import Control.Seq
> 
> mergeSort :: (NFData a, Ord a) => [a] -> [a]
> mergeSort [] = []
> mergeSort [x] = [x]
> mergeSort xs = let (ys, zs)
>                       = foldr (\e (a, b) -> (e:b, a)) ([], []) xs
>                    merge xs [] = xs
>                    merge [] ys = ys
>                    merge s@(x:xs) t@(y:ys)
>                       | x < y = x : merge xs t
>                       | otherwise = y : merge s ys
>                    ys' = mergeSort ys `using` rdeepseq
>                    zs' = mergeSort zs `using` rdeepseq
>                in ys' `par` zs' `par` merge ys' zs'
> 
> main = print $ mergeSort ([1..100] :: [Int])

(Code was not written to be nice, efficient or even correct but to
illustrate the point.)

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110102/7dd498f5/attachment.pgp>


More information about the Libraries mailing list