比方说,我有以下的树数据类型: datatype 'a tree = Empty | Node of 'a * 'a tree * 'a tree;
val x = Node(10, Node(20, Empty, Empty), Node(30, Empty, Empty));
这里,x是int类型树的变量。我想知道的是如何解析和评估树的不同部分只有变量x? 例如,在此功能: fun ad
没有使用大小写表达式(在类的下一节出现),我看不出为什么以下不做快速排序。它在某个地方进入循环,永远不会结束。 splitAt和append已经过测试,但这里是他们的代码。 fun append(xs, ys) =
if null xs
then ys
else (hd xs) :: append(tl xs, ys)
fun splitAt(xs : int list, x : int
这段代码有什么问题? fun expd s:string = if size(s) > 0 then true else false; 错误我收到: - fun exnd s:string = if size(s) > a then true else false;
stdIn:657.1-837.8 Error: unbound variable or constructor: a
Erro
我注意到在SML中有两种定义函数的方法。例如,如果你把add函数,这是两个方面: val add = fn : int -> int -> int
第二个创建函数类型: fun add x y = x+y;
fun add(x,y) = x+y;
与第一种方法创建函数类型 val add = fn : int * int -> int
这两种类型对于相同功能有什么区别?还有为什么有
三叉树类型被定义为: datatype ’a tree =
Leaf of ’a
| Node of ’a tree * ’a tree * ’a tree
我需要修改功能映射&与foldl相匹配的三叉树... fun tree_map (f : ’a -> ’b) (t : ’a tree) : ’b tree =
f,nil) = nil
| map (f,x::xs) = f(x