[Haskell-cafe] Re: Handles with their IOMode in their type

Lee Houghton gmane at asztal.net
Tue Dec 8 13:22:41 EST 2009

On 08/12/2009 03:54, Bas van Dijk wrote:
> Could not get to sleep tonight so I got up and hacked this together:
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=13782
> Does something like this already exist on hackage:
> If not, I may turn this into a package and upload it tomorrow.
> Comments, criticism and patches are welcome.
> regards,
> Bas

I like this idea.

A small observation, though:

> stdin :: ReadModes ioMode => Handle ioMode
> stdin = Handle SIO.stdin

This allows writing to stdin by choosing ReadWriteMode as the ioMode. I think it would be better to have just
> stdin :: Handle ReadMode

*HandleExplicitIOMode> hPutStrLn (stdin :: Handle ReadWriteMode) "This shouldn't typecheck!"
*** Exception: <stdin>: hPutStr: illegal operation (handle is not open for writing)

This also shows another reason for stdin, stdout and stderr to be monomorphic:

> hGetLine stdin
     Ambiguous type variable `ioMode' in the constraint:
       `ReadModes ioMode'
         arising from a use of `hGetLine' at <interactive>:1:0-13
     Probable fix: add a type signature that fixes these type variable(s)

More information about the Haskell-Cafe mailing list