1
votes

I have a list of Text :

foo :: [Text]
foo = ["Foo", "Bar"]

I use scotty's json function to send the response.

post "/generate" $ do
     json foo

I get No Instance Error:

 No instance for (ToJSON Text) arising from a use of ‘json’

When I added :

instance ToJSON Text  where
        toJSON = String
instance FromJSON Text where
        parseJSON = withText "Text" pure

I get :

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

Seems like I have multiple versions of text-* installed, and I'm stuck.

1
Are you using a cabal sandbox? This looks like the base issue is cabal hell. - bheklilr
It's also pretty weird that you're having to define your instances for Text, since those definitely already exist in Data.Aeson. - bheklilr
@bheklilr : I'm not using a sandbox - 'll try it to see if that fixes this. Also, I'm defining my instances cuz it gave me the No Instance Error, no idea why is that so. - Shanthakumar

1 Answers

0
votes

You are trying to use an aeson that is linked with text-1.1.1.3 on values from text-1.2.0.0 (most likely the version of text you installed last).

You probably want to cabal reinstall aeson, and any packages that breaks.

An alternative is to use cabal to build your project and use a version bound in your .cabal file to force using text-1.1.1.3, but that's almost certainly not what you want to do.