Re: [Haskell-cafe] Re: Handles with their IOMode in their type
On Tue, Dec 8, 2009 at 7:22 PM, Lee Houghton gm...@asztal.net wrote: I like this idea. Thanks 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 interactive:1:0: 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) Rightly spotted, thanks! I will change the types to: stdin :: Handle ReadMode stdout :: Handle WriteMode stderr :: Handle WriteMode Or are there scenarios where people want to write to stdin or read from stdout or stderr? I think I will also rename the IOMode constructors to their System.IO.IOMode equivalents. Then I will also have to rename the ioMode types like so: data IOMode ioMode where ReadMode :: IOMode R WriteMode :: IOMode W AppendMode :: IOMode A ReadWriteMode :: IOMode RW Then there are two decisions I still have to make: 1) How to name the module? What about: System.IO.ExplicitIOModes? 2) What to export? Do I only need to export the changed functions and types like I have now: http://hpaste.org/fastcgi/hpaste.fcgi/view?id=13782 or do I need to export all the other things that System.IO exports. In the latter case users have the advantage that they can just swap their import of System.IO with System.IO.ExplicitIOModes When I have time I will put this in a package and upload it to hackage. Oh yes, final question: how to name this package? What about explicit-iomodes? regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Handles with their IOMode in their type
On Dec 9, 2009, at 16:51 , Bas van Dijk wrote: I will change the types to: stdin :: Handle ReadMode stdout :: Handle WriteMode stderr :: Handle WriteMode Or are there scenarios where people want to write to stdin or read from stdout or stderr? These situations *do* come up; the controlling terminal for a program is open read/write on all 3 file descriptors initially, ands programs like more/less/pg rely on this and do their I/O on stdout. Additionally, on *BSD pipes are actually socketpairs and therefore bidirectional, and a small number of programs rely on this. But I would not do that by default, just expose a way for programs to make it so if they wish. (Hm, just discovered that the System.Posix.IO wrapper for fcntl() does *not* expose the part of the result of F_GETFL that reports the open mode. Boo hiss.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Handles with their IOMode in their type
On Wed, Dec 9, 2009 at 6:00 PM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On Dec 9, 2009, at 16:51 , Bas van Dijk wrote: I will change the types to: stdin :: Handle ReadMode stdout :: Handle WriteMode stderr :: Handle WriteMode Or are there scenarios where people want to write to stdin or read from stdout or stderr? These situations *do* come up; the controlling terminal for a program is open read/write on all 3 file descriptors initially, ands programs like more/less/pg rely on this and do their I/O on stdout. Additionally, on *BSD pipes are actually socketpairs and therefore bidirectional, and a small number of programs rely on this. I was surprised to hear this, so I did some fact checking: http://books.google.com/books?id=rHyMRyDEG3gCpg=PA39lpg=PA39dq=posix+write+to+stdinsource=blots=vHsgioIR8Jsig=PPXTzuwuuxyx_peCnuSNVmE220Ihl=enei=o6cgS-DxJ5S0sgPSl82kBQsa=Xoi=book_resultct=resultresnum=3ved=0CA8Q6AEwAjgK#v=onepageq=f=false Looks like you're telling the truth. Learn something new every time I read Haskell-Cafe :) Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Handles with their IOMode in their type
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 interactive:1:0: 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) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe