I want to write a function that takes a filename as a string and a list of pairs of characters. This function must open the named file, read the contents of the file, and echo the characters to the screen. Any occurrence of a character in the first position of a pair must be echoed as the character in the second position of the pair. For example, an invocation such as fileSubst "inputFile" [(#"a", #"b"), (#"b", #"z")] will echo the contents of inputFile with all occurrences of the character a replaced by the character b and all occurrences of the character b replaced by character z.
fun fileSubst (fileName : string, []) = nil
| fileSubst (fileName, (a,b)::cs) = let
val stream = TextIO.openIn fileName
TextIO.input1 = fileSubst (fileName,cs) in if isSome a
then print(Char.toString(a)) else TextIO.print end ;