[Haskell] Why is newChan in the IO Monad?

Nick Benton nick at microsoft.com
Fri Apr 23 12:46:13 EDT 2004


Channels have identity, so allocating a new one is a side effecting
operation. Having it outside the IO monad would require (for example):

(newChan, newChan) = (let x = newChan in (x,x))

which is wrong. If you wrap newChan in unsafePerformIO then the compiler
will feel free to apply rewrites like the above, which is unlikely to be
what you wanted.

  Nick
-----Original Message-----
From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org]
On Behalf Of S. Alexander Jacobson
Sent: 23 April 2004 19:22
To: Haskell Mailing List
Subject: [Haskell] Why is newChan in the IO Monad?

Nothing actually happens when newChan is called
except construction of a new datastructure.  It
would be nice to have non IO monad code be able to
create a new Chan that gets passed to IO code that
uses it somewhere else.

Alternatively, is there a way to create a Chan
outside the IO monad?

-Alex-

_________________________________________________________________
S. Alexander Jacobson                  mailto:me at alexjacobson.com
tel:917-770-6565                       http://alexjacobson.com
_______________________________________________
Haskell mailing list
Haskell at haskell.org
http://www.haskell.org/mailman/listinfo/haskell


More information about the Haskell mailing list