[MLton] Bug: TextPrimIO does not distinguish between EOF and no data

Ville Laurikari ville at laurikari.net
Thu Dec 13 10:01:24 PST 2007


On Thu, Dec 13, 2007 at 07:46:36AM -0600, Matthew Fluet wrote:
> Someone should check whether similar logic needs to be pushed to the
> StreamIO layer.  (I haven't.)

StreamIO (from basis/io/stream-io.fun) does seem to work already:

   fun loop stream =
       case TextIO.StreamIO.canInput (stream, 1) of
          NONE => (print "Would block.\n"
                 ; OS.Process.sleep (Time.fromSeconds 1)
                 ; loop stream)
        | SOME _ =>
          case TextIO.StreamIO.inputLine stream of
             SOME (line, stream) => (print line
                                   ; loop stream)
           | NONE => print "EOF\n"
   val () = loop (TextIO.getInstream TextIO.stdIn)

   $ mlton nobug.sml
   $ (echo foo; sleep 1; echo bar; sleep 1) | ./bug
   foo
   Would block.
   bar
   Would block.
   EOF
   $

I think I'll make these into a regression test...

--
http://www.iki.fi/vl/



More information about the MLton mailing list