Oct 13, 2003 ------------- - More on ML: topics covered today - input/output - among the impure features of ML - use of "print" command - only prints strings! - use Int.toString, Real.toString etc. to get proper casting - use "carets" (^) for string concatenation - using pre-defined ML structures - TextIO, Char, String - how to prevent over-riding of functions - reading from files, tokenizing - writing to files ------------------------------ - print "hello"; helloval it = () : unit - print 23; stdIn:18.1-18.9 Error: operator and operand don't agree [literal] operator domain: string operand: int in expression: print 23 - print(Int.toString(23) ^ "\n"); ------------------------------ open TextIO; val myfile = openIn("input.txt"); fun readeverything(f) = if endOfStream(f) then nil else inputLine(f)::readeverything(f); fun breakasingleline(s) = String.tokens Char.isSpace s; val s = readeverything(myfile); map breakasingleline s; closeIn(myfile); ------------------------------ val myfile = openOut("output.txt"); output(myfile,"hidden treaasure is buried here\n"); closeOut(myfile);