throwDyn typing "fun"

Previous Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

throwDyn typing "fun"

Einar Karttunen
Hello

It seems that the type of throwDyn and throwDynTo are dangerously close.
ThrowDyn works in with any of the arguments of throwDynTo, which can
cause evil situations.

throwDyn :: Typeable exception => exception -> b

Which means e.g. "throwDyn someThreadId SomeException" will work
when you wanted to say "throwDynTo someThreadId SomeException"
and they both have types which unify with IO ().

I think using a
class Typeable => DynamicException a where ...
and throwDyn :: DynamicException a => a -> b
could make more sense.

- Einar Karttunen
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: throwDyn typing "fun"

Tomasz Zielonka
On Fri, Nov 11, 2005 at 01:20:05PM +0200, Einar Karttunen wrote:
> It seems that the type of throwDyn and throwDynTo are dangerously close.
> ThrowDyn works in with any of the arguments of throwDynTo, which can
> cause evil situations.
>
> throwDyn :: Typeable exception => exception -> b
>
> Which means e.g. "throwDyn someThreadId SomeException" will work
> when you wanted to say "throwDynTo someThreadId SomeException"
> and they both have types which unify with IO ().

How evil! ;-)

> I think using a
> class Typeable => DynamicException a where ...
> and throwDyn :: DynamicException a => a -> b
> could make more sense.

You could also do something like:

    newtype Exn a = Exn a -- not Typeable

    throwDyn' :: Typeable exception => Exn exception -> b
    throwDyn' (Exn e) = throwDyn e

used as

    throwDyn' (Exn (some-typeably-thingy))

then neither (throwDyn' someThreadId SomeException) nor
(throwDyn' someThreadId (Exn SomeException)) will compile.

And you won't have to create instances of DynamicException, but it is
probably more ugly.

Best regards
Tomasz
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe