[Haskell] Re: IO Regions in Haskell98
oleg at pobox.com
oleg at pobox.com
Wed Jan 25 19:23:35 EST 2006
>testMinus1 = join $ runIOM $ withFile "/etc/motd" $
> return . runIOM . qGetChar
Isn't this the same situation we have in Haskell98 with respect to the
regular IO? The safety of IO depends on the fact that the IO type
constructor cannot be eliminated. Hence the 'main' trick, hence the
only function that can eliminate IO is named 'unsafe'.
If we wish for the safe runIOM, we have to enforce the same guarantees
as we have in the ST monad regarding runST. That of
course, cannot be done in Haskell98 (although the resulting library
can be used in Haskell98 code). It should be emphasized that the
Typeable constraint has reduced the problem of 'region nesting' to the
regular problem of the 'linearity' of computations -- which is already
solved in ST monad. We can add that pervasive 's' type parameter to
our Q and IOM types. However, the simpler approach is just to use our
'mark' as that 's' parameter.
So, the only changes are changes in the type signatures:
withFile :: Typeable a => FilePath -> (Q mark -> IOM mark a) -> IOM mark a
runIOM :: (forall mark. IOM mark a) -> IO a
(and adding -fglasgow-exts flag, which is not-viral: the code that
uses IO regions can remain Haskell98). Luckily, polymoprhic types,
such as |IOM mark a| must be with respect to |mark|, cannot be
instances of Typeable, so our safety constraint is automatically
satisfied. I knew the polymorphic restriction on Typeable must be good
for something.
More information about the Haskell
mailing list