I have to write a code that takes integer list and writes them to a file. At the same time it returns true if the element is written, else false if it is not written.
I wrote something like
fun writetofile([],sfile)= false
|writetofile((l:int)::ls, sfile)=
let
val outs=TextIO.openOut(sfile)
fun writeinline(outs,[])=(false;TextIO.closeOut(outs))
|writeinline(outs,(l:int)::ls)=(true;TextIO.output(outs,(Int.toString(l)^"\n"));writeinline(outs,ls))
in
writeinline(outs,l::ls) before
TextIO.closeOut(outs)
end
;
I got following error:
Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
expression: unit
result type: bool
in declaration:
writeNums =
(fn (nil,sfile) => true
| (:: <pat>,sfile) =>
let val <binding>
val <binding> in (<exp>; <exp>) end)