[Haskell-cafe] Just for a laugh...

rossberg at ps.uni-sb.de rossberg at ps.uni-sb.de
Fri Jun 1 15:14:37 EDT 2007


David Roundy wrote:
> On Fri, Jun 01, 2007 at 07:39:32PM +0100, Andrew Coppin wrote:
>>
>> No, I mean... how could you use unsafePerformIO to perform a typecast? I
>> don't see a way to do that.
>
> Then I'm confused.  What typecast are you talking about?

cast :: a -> b
cast x = unsafePerformIO (do writeIORef r x; readIORef r)
         where r = unsafePerformIO (newIORef undefined)

The problem is that the Hindley/Milner type inference algorithm is unsound
in the presence of effects - r may not be given polymorphic type. That's
exactly the reason for ML's dreaded value restriction.

- Andreas




More information about the Haskell-Cafe mailing list