1

みなさん、こんにちは。私はこのコードスニペットを持っています。

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] <- fn is the composition of the function n timesが、エラーが発生するたびに次のようになります。

- 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>))
- 

誰か助けてくれませんか、よろしくお願いします

4

1 に答える 1

1

関数適用は-演算子よりも優先順位が高いため、compList f n-1として解析され(compList f n) - 1ますが、これは明らかにあなたが望むものではありません。

あなたは書く必要がありますcompList f (n-1)

于 2010-11-28T12:26:16.423 に答える