Haskell记录语法并从文件中读取.记录语法的字符串.***例外:Prelude.read:没有解析

Beh*_*tx3 3 syntax haskell exception record

我有下面的记录语法.

type Title = String
type Author = String
type Year = Int
type Fan = String


data Book = Book { bookTitle :: Title
                 , bookAuthor:: Author
                 , bookYear  :: Year
                 , bookFans  :: [Fan]
                 }
                 deriving (Show, Read)


type Database = [Book]

bookDatabase :: Database 
bookDatabase = [Book "Harry Potter" "JK Rowling" 1997 ["Sarah","Dave"]]
Run Code Online (Sandbox Code Playgroud)

我想创建一个IO函数来读取books.txt文件并将其转换为类型数据库.我认为它需要与我下面的尝试相似.

main :: IO()
main = do fileContent <- readFile "books.txt";
          let database = (read fileContent :: Database)
Run Code Online (Sandbox Code Playgroud)

books.txt文件的格式是什么?

下面是我目前的books.txt内容(与bookDatabase相同).

[Book "Harry Potter" "JK Rowling" 1997 ["Sarah","Dave"]]
Run Code Online (Sandbox Code Playgroud)

***例外:Prelude.read:没有解析

Cir*_*dec 6

Read记录的派生实例只能读取记录语法.它无法读取按顺序应用于参数的构造函数格式的记录.尝试将以下(这是结果show bookDatabase)放入books.txt.

[Book {bookTitle = "Harry Potter", bookAuthor = "JK Rowling", bookYear = 1997, bookFans = ["Sarah","Dave"]}]
Run Code Online (Sandbox Code Playgroud)