私は自分で定義したこのタイプを持っています:
data Item =
Book String String String Int -- Title, Author, Year, Qty
| Movie String String String Int -- Title, Director, Year, Qty
| CD String String String Int deriving Show -- Title, Artist, Year, Qty
空のリストを作成しました
all_Items = []
次の関数を使用して、Item(Book)タイプの新しい本をall_Itemsに挿入しようとしています。
addBook all_Items = do
putStrLn "Enter the title of the book"
tit <- getLine
putStrLn "Enter the author of the book"
aut <- getLine
putStrLn "Enter the year this book was published"
yr <- getLine
putStrLn "Enter quantity of copies for this item in the inventory"
qty <- getLine
Book tit aut yr (read qty::Int):all_Items
return(all_Items)
ただし、次のエラーが発生します。
Couldn't match expected type `IO a0' with actual type `[a1]'
エラーは、consing演算子を使用して新しい本をリストに追加している行を示しています。タイプエラーであることがわかりますが、何が間違っているのか、どのように修正すればよいのかわかりません。前もって感謝します!