【发布时间】:2012-12-17 05:14:43
【问题描述】:
我要编写以下代码并且我使用 SML/NJ:
signature STACK=
sig
type 'a Stack
val empty :'a Stack
val isEmpty : 'a Stack -> bool
val cons : 'a*'a Stack -> 'a Stack
val head : 'a Stack ->'a
val tail : 'a Stack -> 'a Stack
val ++ : 'a Stack * 'a Stack -> 'a Stack
end
structure List : STACK =
struct
infix 9 ++
type 'a Stack = 'a list
val empty = []
fun isEmpty s = null s
fun cons (x,s) = x::s
fun head s = hd s
fun tail s = tl s
fun xs ++ ys = if isEmpty xs then ys else cons(head xs, tail xs ++ ys)
end
我想使用解释器中的 ++ 运算符,但是当我编写 s1 List.++ s2 其中 s1 和 s2 堆栈类型时,我得到了运算符不是函数的消息。
谢谢。
【问题讨论】:
标签: smlnj