有些人可以解释以下几页的代码错误。 这部法律试图在接收用户的意见时执行《商业仲裁示范法》的序幕。
import System.IO
loop :: Int -> [Int] -> IO [Int]
loop 0 ls = return ls
loop n ls = do newNumber <- readLn
loop (n-1) (newNumber:ls)
data Tree a = EmptyTree | Node a ( Tree a) ( Tree a) deriving ( Show,Read, Eq)
singleton :: a -> Tree a
singleton x = Node x EmptyTree EmptyTree
treeInsert :: ( Ord a) => a -> Tree a -> Tree a
treeInsert x EmptyTree = singleton x
treeInsert x ( Node a left right)
| x==a = Node x left right
| x<a = Node a (treeInsert x left) right
| x>a = Node a left (treeInsert x right)
inorder :: Tree a -> [a]
inorder EmptyTree = []
inorder (Node a left right) = inorder left ++ [a] ++ inorder right
main = do
putStrLn " Please enter the number"
number <- readLn :: IO Int
putStrLn $ "The num is:" ++ show number
xs <- loop number []
let numtree = foldr treeInsert EmptyTree xs
print numtree
ys <- inorder numtree
print ys
错误一是:
Couldn t match expected type `IO t0 with actual type `[a0]
In the return type of a call of `inorder
In a stmt of a do expression: ys <- inorder numtree
In the expression:
do { putStrLn " Please enter the number";
number <- readLn :: IO Int;
putStrLn $ "The num is:" ++ show number;
xs <- loop number [];
.... }