[Haskell-beginners] IO vars

Brent Yorgey byorgey at seas.upenn.edu
Wed Aug 29 12:55:19 CEST 2012

On Wed, Aug 29, 2012 at 12:00:50PM +0200, Corentin Dupont wrote:
> Thanks Eugene and Ozgur.
> I also looked on the side of IORef, but it doesn't looked to be a good
> solution since we have to use unsafePerformIO.
> I have a big program to modify, and I want to pass some new data to
> existing functions of type IO(). I'd like to avoid changing all the
> function's types down the chain... What is the best way to do that?

There is no good way.  IORef is probably the best, but as you
correctly point out, it is quite ugly.  

The fact that you have to change your program's types is a feature,
not a bug.  One of Haskell's great strengths is that the types make
plain any communication which can take place between different
components.  If you want to go behind the type system's back and add
hidden communication channels, you might as well be writing in C, and
should not be surprised that there is no good way to do it.


More information about the Beginners mailing list