1

再帰関数を実装していますが、停止条件を(2*scope)にする必要があります。これは関数のパラメーターです。

sortByManhattanDistance agent (2*scope) scope xs sortedNearFoodList = sortedNearFoodList

sortByManhattanDistance agent n scope xs sortedNearFoodList = sortByManhattanDistance agent (n+1) scope xs (sorted ++ sortedNearFoodList) 
where sorted=compareManhattanDistance xs agent n

そして抱擁は次のように不平を言います:Syntax error in declaration (unexpected symbol "*") それは、パラメーターに対していくつかの関数を使用できないということですか?

前もって感謝します

4

1 に答える 1

5

いいえ、そのような方程式の左辺で関数や演算子を使用することはできません。

あなたが望むことを行う適切な方法は、ガードを使用することです:

sortByManhattanDistance agent n scope xs sortedNearFoodList
    | n == 2 * scope = sortedNearFoodList
    | otherwise      = sortByManhattanDistance agent (n+1) scope xs
                                            (sorted ++ sortedNearFoodList) 
  where sorted = compareManhattanDistance xs agent n
于 2013-03-31T12:29:31.000 に答える