simonmar / monad-par

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ST monad trick

mitchellwrosen opened this issue · comments

Hi, I was just re-reading your excellent book and came across this warning:

There is nothing in the types to stop you from returning an IVar from runPar and
passing it to another call of runPar. This is a Very Bad Idea; don’t do it. The 
implementation of the Par monad assumes that IVars are created and used 
within the same runPar, and breaking this assumption could lead to a runtime 
error, deadlock, or worse.

The library could prevent you from doing this using qualified types in the same
way that the ST monad prevents you from returning an STRef from runST. This 
is planned for a future version.

Just curious, is this still meant to happen at some point?

I'm not actively working on monad-par, so I doubt this will happen, unless someone else really wants to work on it. It would be a big breaking change for existing users, which could be a problem. I think I was also worried about the extra type clutter this would cause, for limited benefit, but I probably wouldn't object very strongly if someone else were doing the work to push this through.

One option would be to offer extra modules exposing the safer versions. That's a bit of extra clutter on Hackage, but maybe it would be worth it.