我必须编写一个接受整数列表并将它们写入文件的代码。同时如果元素被写入则返回true,否则返回false。
我写了类似的东西
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
;
我收到以下错误:
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)