【发布时间】:2015-08-07 21:52:23
【问题描述】:
ML 之前在 http://sml-family.org/Basis/general.html 中被描述为
a 在 b 之前 返回一个。它提供了一种符号简写,用于评估 a, 然后 b, before 返回 a 的值。
当我尝试使用此命令时,期望 x = 4 和 (4+1) 被评估
val x = (3+1 before 4+1)
我收到错误消息:
Standard ML of New Jersey v110.78 [built: Sun Apr 26 01:06:11 2015]
- stdIn:1.11-1.25 Error: operator and operand don't agree [overload conflict]
operator domain: [+ ty] * unit
operand: [+ ty] * [+ ty]
in expression:
(3 + 1 before 4 + 1)
-
可能出了什么问题?
编辑
根据马特的回答,我应该使用
val x = (3+1 before print "<end>")
我还发现before是用来在处理完一些FileIO函数后关闭流的。
(* http://stackoverflow.com/questions/2168029/open-file-in-mlsmlnj *)
val infile = "input.txt" ;
(* reading from file follow this to list of string per line *)
fun readlist (infile : string) = let
val ins = TextIO.openIn infile
fun loop ins =
case TextIO.inputLine ins of
SOME line => line :: loop ins
| NONE => []
in
loop ins before TextIO.closeIn ins
end ;
val pureGraph = readlist(infile);
size (hd pureGraph)
【问题讨论】:
-
"and (4+1) isevaluate" 你预计
4+1的评估会有什么效果?您是想要打印结果还是只想计算结果并丢弃?