我正在导入此内容:
import Data.Aeson (ToJSON(..), FromJSON(..), (.:), (.=), object, Object(..), decode)
我有这个:
instance FromJSON Data123 where
parseJSON (Object v) =
Data123 <$> v .: "a"
<*> v .: "b"
<*> v .: "c"
parseJSON _ = mzero
instance ToJSON Data123 where
toJSON (Data123 a b c) =
object ["a" .= a
, "b" .= b
, "c" .= c
]
我说错误
Not in scope: data constructor ‘Object’
Perhaps you meant variable ‘object’ (imported from Data.Aeson)
我还没有进口它吗?
答案 0 :(得分:10)
信不信由你,尚未导入它。 Object
数据构造函数构造04-26 11:45:04.450: E/AndroidRuntime(2813): FATAL EXCEPTION: main
04-26 11:45:04.450: E/AndroidRuntime(2813): Process: com.clip.android, PID: 2813
04-26 11:45:04.450: E/AndroidRuntime(2813): java.lang.ClassCastException: com.clip.android.ClaimRegister$1$1 cannot be cast to android.app.Dialog
04-26 11:45:04.450: E/AndroidRuntime(2813): at com.clip.android.ClaimRegister$1.onClick(ClaimRegister.java:96)
04-26 11:45:04.450: E/AndroidRuntime(2813): at android.view.View.performClick(View.java:5198)
04-26 11:45:04.450: E/AndroidRuntime(2813): at android.view.View$PerformClick.run(View.java:21147)
04-26 11:45:04.450: E/AndroidRuntime(2813): at android.os.Handler.handleCallback(Handler.java:739)
04-26 11:45:04.450: E/AndroidRuntime(2813): at android.os.Handler.dispatchMessage(Handler.java:95)
04-26 11:45:04.450: E/AndroidRuntime(2813): at android.os.Looper.loop(Looper.java:148)
04-26 11:45:04.450: E/AndroidRuntime(2813): at android.app.ActivityThread.main(ActivityThread.java:5417)
04-26 11:45:04.450: E/AndroidRuntime(2813): at java.lang.reflect.Method.invoke(Native Method)
04-26 11:45:04.450: E/AndroidRuntime(2813): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-26 11:45:04.450: E/AndroidRuntime(2813): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
,因此要导入它,您应该
Value
或类似的。你可能认为你会从
获得它import Data.Aeson (Value(Object))
但实际上这会导入Object
类别别名。从语法上来说,它似乎也试图导入与import Data.Aeson (Object(..))
类型相关联的任何数据构造函数 - 但由于它是别名,因此没有。 (我想我可能更喜欢GHC对此类事情发出警告!)