【发布时间】:2015-10-25 22:38:00
【问题描述】:
我有一个元组列表 [("hi", 1), ("yo", 2)];,我想使用 sml 中的标准输出 print s; 将此列表“转换”为表格。
例如上面的元组列表会产生如下输出:
------------
| "hi" | 1 |
------------
etc...
------------
我有这个代码,但它给了我一个错误:
fun outputTable [] = print "Nothing! \n"
| outputTable ((hd, n)::tl) =
print "-----------"
print "| "^hd^" | "^n^" |"
print "-----------"
outputTable tl;
这是错误:
stdIn:15.2-17.21 Error: operator is not a function [tycon mismatch]
operator: unit
in expression:
(print "-----------") print
stdIn:15.2-17.21 Error: operator is not a function [tycon mismatch]
operator: string
in expression:
" |" outputTable
stdIn:13.5-17.21 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
expression: string
result type: unit
in declaration:
outputTable =
(fn nil =print "Nothing!"
| :: (<pat>,<pat>) =<exp^ <exp^ <exp<exp>)
【问题讨论】: