문제

The .hs code :

data Person = Person { firstName :: String  
                     , lastName :: String  
                     , age :: Int  
                     } deriving (Eq, Show, Read)

Compilation :

*Main> :load "/home/optimight/baby.hs"  
[1 of 1] Compiling Main             ( /home/optimight/baby.hs, interpreted )  
Ok, modules loaded: Main.  

While testing immediately after compilation:

*Main> read "Person {firstName = \"Michael\", lastName \"Diamond\", age = 43}" :: Person  
*** Exception: Prelude.read: no parse

Please guide. Why this error is occurring and how to avoid such errors?

도움이 되었습니까?

해결책

lastName \"Diamond\"

is missing an equals sign.

read "Person {firstName = \"Michael\", lastName = \"Diamond\", age = 43}" :: Person
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top