.hs代码:
data Person = Person { firstName :: String
, lastName :: String
, age :: Int
} deriving (Eq, Show, Read)
编译:
*Main> :load "/home/optimight/baby.hs"
[1 of 1] Compiling Main ( /home/optimight/baby.hs, interpreted )
Ok, modules loaded: Main.
编译后立即测试:
*Main> read "Person {firstName = \"Michael\", lastName \"Diamond\", age = 43}" :: Person
*** Exception: Prelude.read: no parse
请指导。为什么会出现此错误以及如何避免此类错误?
答案 0 :(得分:7)
lastName \"Diamond\"
缺少等号。
read "Person {firstName = \"Michael\", lastName = \"Diamond\", age = 43}" :: Person