0

二分探索でタプルのインデックスリストを検索するプログラムを書きます

superBubble::(Ord t) =>[[t]]->[[t]]
superBubble a=map bubbleSort a
combining::[BookInfo]->[Int]
combining books= bubbleSort(map index books)  
 binsearch :: [Int] -> Int -> Int -> Int -> Int -- list, value, low, high, return int
 binsearch xs value low high
  | high < low       = -1
  | xs!!mid > value  = binsearch xs value low (mid-1)
  | xs!!mid < value  = binsearch xs value (mid+1) high
  | otherwise        = mid
   where
   mid = low + ((high - low) `div` 2)
  final::[BookInfo]->Int->Int->Int->Int 
  final vs key s r= binsearch concat( combining vs) key s r

他の機能は適切に機能しますが、穴に追加するとエラーが発生します

エラーは予期しない '|' です 最初のものですが、なぜですか?

4

1 に答える 1

1

からの行binsearch ::は、前の行より1スペース多くインデントされます。これらの各行のインデントを1スペース分だけ解除します。

さらに、final::以降の行は、最初の行より2スペース多くインデントされます。これらの各行のインデントを2つのスペースで外します。

最後に、ダニエルが指摘しているように、あなたは-<あなたのfinal::行に。の代わりにを持っています->(投稿されたコードで修正したので、将来この質問を見る人を混乱させます。)


正しいコード:

superBubble::(Ord t) =>[[t]]->[[t]]
superBubble a=map bubbleSort a
combining::[BookInfo]->[Int]
combining books= bubbleSort(map index books)  
binsearch :: [Int] -> Int -> Int -> Int -> Int -- list, value, low, high, return int
binsearch xs value low high
 | high < low       = -1
 | xs!!mid > value  = binsearch xs value low (mid-1)
 | xs!!mid < value  = binsearch xs value (mid+1) high
 | otherwise        = mid
  where
  mid = low + ((high - low) `div` 2)
final::[BookInfo]->Int->Int->Int->Int 
final vs key s r= binsearch concat( combining vs) key s r

bubbleSort(そして、、の定義も含める必要がありますBookInfoindex


インデントがエラーになるのはなぜですか?

Because it makes binsearch look as if it is part of the value of combining, instead of a separate function. The first | is the first character that can't possibly be part of an expression.

于 2012-07-18T13:28:36.927 に答える