{-# OPTIONS -fglasgow-exts #-} -- Simple IO Regions. Tests -- Attempt to break the safety guarantees by using encapsulated polymorphic -- types -- $Id: IORegions98Test1.hs,v 1.1 2006/01/24 00:42:08 oleg Exp oleg $ module IORegions98Test1 where import IORegions98E import Monad import Data.Typeable -- We define the following just as an attempt to break the safety -- guarantee. Users should NOT add the following two instances. -- However, even if they do, the safety guarantees still hold instance Typeable1 Q instance Typeable2 IOM data W1 a = W1 (forall marks. IOM marks a) data W2 = W2 (forall marks. Q marks) data W3 a = W3 (forall marks. Q marks -> IOM marks a) instance Typeable1 W1 -- Hugs likes the commented-out instance -- instance Typeable a => Typeable (W3 a) instance Typeable1 W3 instance Typeable W2 -- test1 = withFile "/etc/motd" (\q -> return $ W2 q) -- test2 = withFile "/etc/motd" (\q -> return $ W1 (qGetChar q)) test3 = withFile "/etc/motd" (\q -> return $ W3 (qGetChar)) -- test4 = withFile "/etc/motd" (\q -> return $ W3 (\q1 -> qGetChar q)) {- Of course the guarantees break if we add -fallow-incoherent-instances and define instance Typeable a But in that case, the total function coerce :: a -> b becomes expressible, which breaks all guarantees in Haskell whatsoever. See the message on the Haskell list on Jan 26, 2006. -}