【发布时间】:2014-10-21 14:04:44
【问题描述】:
我有一个文本列表:
foo :: [Text]
foo = ["Foo", "Bar"]
我使用 scotty 的 json 函数来发送响应。
post "/generate" $ do
json foo
我收到无实例错误:
No instance for (ToJSON Text) arising from a use of ‘json’
当我添加时:
instance ToJSON Text where
toJSON = String
instance FromJSON Text where
parseJSON = withText "Text" pure
我明白了:
Couldn't match type ‘text-1.1.1.3:Data.Text.Internal.Text’
with ‘Text’
NB: ‘text-1.1.1.3:Data.Text.Internal.Text’
is defined in ‘Data.Text.Internal’ in package ‘text-1.1.1.3’
‘Text’
is defined in ‘Data.Text.Internal.Lazy’ in package ‘text-1.2.0.0’
Expected type: Text -> Value
Actual type: text-1.1.1.3:Data.Text.Internal.Text -> Value
In the expression: String
In an equation for ‘toJSON’: toJSON = String
好像我安装了多个版本的 text-*,但我被卡住了。
【问题讨论】:
-
你在使用阴谋集团沙箱吗?这看起来像基本问题是阴谋集团的地狱。
-
您必须为
Text定义实例也很奇怪,因为这些实例肯定已经存在于Data.Aeson中。 -
@bheklilr :我没有使用沙箱——我会尝试看看是否能解决这个问题。另外,我正在定义我的实例,因为它给了我No Instance Error,不知道为什么会这样。
标签: haskell