[Haskell-cafe] TVars & throw

Thomas Conway drtomc at gmail.com
Thu Mar 8 16:33:31 EST 2007


On 3/8/07, Chris Kuklewicz <haskell at list.mightyreason.com> wrote:
> What happens in your throw/catch case if I have
>   stm1 = do some_stm_code_that_throws_your_exception
>   stm2 = return Foo
> and I run "atomically (stm1 `orElse` stm2)" ?
> Answer: The exception will prevent running stm2.

In the *specific* case of the external dictionary code, there is no
orElse case to worry about since the algorithms are deterministic in
this sense. For a more general case, it is an interesting problem to
consider. You might want something like
throwIfNothingElseSeemsLikeAGoodIdea, so that you can attempt any
alternatives, and if none succeed then throw (and I guess choose the
first if more than one alternative wants to throw - I like
determinism).

> > Um, is
> >    unsafeIOToSTM $ atomically trans
> > going to run you into problems?
>
> YES!

My point is that onRetry really wants to be not "IO t" but
"IO_execpt_STM t", but there's no way of ensuring that, which
unfortunately antagonizes modularity in the same kind of way that
locks do.  It requires you to know how the implementation of the IO
actions you use work, in case they use STM inside. Since the actions
may come out of a library somewhere, you need to know how the library
is implemented.

<sigh> Why are tricky problems tricky? I thought Haskell was supposed
to make everything easy. ;-)

T.
-- 
Dr Thomas Conway      You are beautiful; but learn to work,
drtomc at gmail.com         for you cannot eat your beauty.
                                              -- Congo proverb


More information about the Haskell-Cafe mailing list