sml - output file to stdin -


how 1 output characters in file stdin in sml/nj? here have far i'm stuck i'm getting errors thrown @ me compiler.

code:

fun outputfile infile = let    val ins = textio.openin infile;    fun helper copt =    case copt of       none = textio.closein ins;       | some(c) = textio.output1(stdin,c);          helper(textio.input1 ins)); in    helper ins end; 

any thoughts i'm going wrong?

well, depends on trying file input. if want print characters read file, without outputting file, can print output:

fun outputfile infile = let   val ins = textio.openin infile;    fun helper copt = (case copt of none => textio.closein ins                       | c => print (str c); helper (textio.input1 ins)); in   helper (textio.input1 ins) end;   outputfile "outtest";    (*if name of file "outtest" call way*) 

however, above example bad, since give infinite loop, when hits none, not know how terminate , close file. therefore, version cleaner, more readable, , terminates:

fun outputfile infile = let   val ins = textio.openin infile;    fun helper none = textio.closein ins      | helper (some c) = (print (str c); helper (textio.input1 ins));  in   helper (textio.input1 ins) end;   outputfile "outtest"; 

if want output contents of infile file, that's story , have open file handle output in case.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -