[Haskell] Real life examples

Lennart Augustsson lennart at augustsson.net
Thu Nov 25 04:53:46 EST 2004


I don't necessarily agree that you can do this trick
in all implementations of Dynamic and Typable.
You're relying on more things than the interface to
Dynamic promises.  Your fromDynamic could very well
return Nothing.  And should!

But that doesn't matter.  The unsafeCast function doesn't
really worry my much.  It's unsafePerformIO that worries me.
Using unsafe casts just makes us program in the untyped
lambda calculus, where the beta rule still holds, so no
worries.  Whereas unsafePerformIO opens an entirely different
can of worms.

	-- Lennart

George Russell wrote:
> Lennart wrote (snipped):
>  > An "easy" way to
>  > prove it is to provide an equivalent implementation that uses only
>  > pure functions.  As far as I remember Control.Monad.ST can be written
>  > purely.  And I think the same is true for Data.Dynamic.
> 
> I don't see how it can be, since you can use Data.Dynamic to provide an
> unsafe function
>    cast : a -> b
> 
> newtype UnsafeCast a = UnsafeCast a
> 
> instance Typeable (UnsafeCast a) where
>    typeOf _ = mkAppTy (mkTyCon "") []
> 
> cast :: a -> b
> cast a =
>    let
>       Just (UnsafeCast b) = fromDynamic (toDyn (UnsafeCast a))
>    in
>       b
> 



More information about the Haskell mailing list