我试图在SML中使用foldr或foldl建立一个函数,它将返回列表中所有元素的逻辑或逻辑。 我试图以这种方式,使用和和或: fun band x = foldr (op and) true x;
fun bor x = foldr (op or) false x;
而且还使用andalso和否则别指望。不过,我不断收到错误消息,例如: Error: unbound variable or
我没那么熟悉SML但我已经写了下面的程序: datatype 'a bin_tree = Leaf of 'a
| Node of 'a bin_tree * 'a bin_tree
fun height Leaf (x) = 0
| height Node (l1,l2) = 1 + Int.max(l1,l2)
fun is_balanced Leaf (x) = true
|
该函数将实数的列表保存到文件: fun writeReal (real, filename) =
let val fd = TextIO.openOut filename
val _ = map (fn i => TextIO.output (fd, Real.toString i^"\r\n")) real
val _ = TextIO.closeOut fd
如何引用从函子的结果派生类型的结构中使用的签名中的类型。下面是使用聚解释一个例子: > signature Res = sig type f end;
signature Res = sig type f end
> functor F (A: sig type t end) : Res = struct datatype f = None | Some end;
functor F (A:
标准ML中是否有可能重新导出作为函数参数接收的结构的一部分的数据类型的构造函数。某些代码可能会使这更容易理解: signature FLAG =
sig
type t
end
signature MEMBER =
sig
structure Flag : FLAG
end
functor Member(F : FLAG) : ME