[Haskell] Why is newChan in the IO Monad?

Sebastian Sylvan sylvan at dtek.chalmers.se
Fri Apr 23 21:31:14 EDT 2004



S. Alexander Jacobson wrote:

> 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?
> 

I'm sure I'll get death threats for posting this but here it goes:

C:\>hugs
__   __ __  __  ____   ___     _________________________________________
||   || ||  || ||  || ||__     Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||    Copyright (c) 1994-2003
||---||         ___||          World Wide Web: http://haskell.org/hugs
||   ||                        Report bugs to: hugs-bugs at haskell.org
||   || Version: Nov 2003       _________________________________________

Haskell 98 mode: Restart with command line option -98 to enable extensions

Type :? for help
Prelude> :l IOExts
IOExts> :t unsafePerformIO
unsafePerformIO :: IO a -> a
IOExts>



Personally I think the usage of unsafePerformIO is fine (but don't 
overuse it!). It's akin to the unsafe keyword in C#. All you're really 
doing is saying "Look, GHC, I know you don't like this stuff but I 
_promise_ that this code won't screw anything up for you", and as the 
programmer you should be allowed to say that every now and then.

/S

-- 
Clothes make the man. Naked people have little or no influence on society.
- Mark Twain


More information about the Haskell mailing list