我选择二进制搜索记录数组索引作为我的研究生研究的 c++ 和 haskell 我编写c++ 代码并工作,现在我为 haskell 工作
import Data.List
data BookInfo = Book Int String [String]
deriving (Show)
--输入变量
entering :: Int String [String]-> Book
entering id name subject= Book id name subject
--创建元组数组的索引
index :: [Book]->[Int]
index [m] = getID (Book id _ _ ) = id
main :: IO ()
main = do
putStrLn "Please enter your book id,name,Subject"
Book inpStr <- getLine
putStrLn print r
-- 使用地图的冒泡排序
bubbleSort ::(Ord x) => [x] -> [x]
bubbleSort (x':xs) = if x>x' then x': bubbleSort(x:xs)
else
if x<x' then x: bubbleSort(x':xs)
else
x: bubbleSort(X':xs)
bubble ::[a] -> [a]
bubble [a] = map bubbleSort [a]
--为数组创建索引
indexsort(ord a)::[int]->[Int]
indexsort a=bubble a
--制作元组列表
addBooks2List Book->[Book]->[Book]
addBooks2List b m=b:entering b':m
--二进制搜索
binarysearch [Int]->Int->Int->Int->Int
a=bubble x
binaryseach a i m j=
let u=(i+m)/2
if a[u]=j then u
if a[u]>j then binaryseach a i u-1 j
else
if a[u]<j then binarysearch a u+1 m j
if i=m "Not found"
--打印具有搜索到的 id 的元组
print::Int->Book
print r= Book r y z
r=binaryseach m 0 (length m)
它在输入“输入”时在 8:3 解析错误时出错这个错误是什么意思?以及如何纠正它?