NJ的SML中存在错误

NJ的SML中存在错误,sml,smlnj,Sml,Smlnj,大家好,我有一段代码: local fun NTimesF(f, n:int) = if n = 1 then fn (x) => f(x) else fn (x) => f(NTimesF(f, n - 1)(x)) in fun compList f n = if n = 0 then [] else (NTimesF(f, n)) :: (compList f n-1) end; 我需要编写一个程序,接收一些

大家好,我有一段代码:

local
 fun NTimesF(f, n:int) = 
    if n = 1 then fn (x) => f(x)
    else fn (x) => f(NTimesF(f, n - 1)(x))
in  
 fun compList f n = if n = 0  then []
                    else (NTimesF(f, n)) :: (compList f n-1)
end;
我需要编写一个程序,接收一些函数f和整数n,并生成函数列表,如
[f1,f2,…fn]'Z)*('Z->'Z)列表
操作数:('Z->'Z)*int
在表达上:
NTimesF(f,n):(compList f)n-1
stdIn:6.6-7.46错误:子句右侧与函数结果类型[literal]不一致
表达式:int->list
结果类型:int->int
在声明中:
compList=(fn arg=>(fn=>))
- 

有人能帮助我吗,提前谢谢

因为函数应用程序的优先级高于
-
运算符,
compList f n-1
被解析为
(compList f n)-1
,这显然不是您想要的


您需要编写
compList f(n-1)

因为函数应用程序的优先级高于
-
运算符,
compList f n-1
被解析为
(compList f n)-1
,这显然不是您想要的


您需要编写
compList f(n-1)

非常感谢,您是如何注意到的?你熟悉ML吗?@rookie:是的,我熟悉ML(否则我就不会浏览sml标签;-)。此外,错误消息会告诉您错误在哪里,如果仔细观察,它还会告诉您表达式是如何解析的。因此,通过一点经验,很容易发现错误。非常感谢,您是如何注意到的?你熟悉ML吗?@rookie:是的,我熟悉ML(否则我就不会浏览sml标签;-)。此外,错误消息会告诉您错误在哪里,如果仔细观察,它还会告诉您表达式是如何解析的。因此,从那里很容易找到一点经验的错误。
- stdIn:7.11-7.46 Error: operator and operand don't agree [literal]
  operator domain: ('Z -> 'Z) * ('Z -> 'Z) list
  operand:         ('Z -> 'Z) * int
  in expression:
    NTimesF (f,n) :: (compList f) n - 1
stdIn:6.6-7.46 Error: right-hand-side of clause doesn't agree with function result type [literal]
  expression:  int -> _ list
  result type:  int -> int
  in declaration:
    compList = (fn arg => (fn <pat> => <exp>))
-