fakedata-haskell / fakedata

Haskell Library for producing quality fake data
BSD 3-Clause "New" or "Revised" License
149 stars 22 forks source link

`aeson-2` support #41

Closed ocharles closed 2 years ago

ocharles commented 2 years ago

This is a bit of a weird one! Because fakedata depends on yaml, it indirectly depends on aeson. However, yaml just re-exports combinators like .: from aeson. Therefore, depending on the solvers choice of aeson, fakedata might or might not build. If aeson-2 is chosen, then fakedata will fail to build with:

[275 of 367] Compiling Faker.Provider.Adjective ( src/Faker/Provider/Adjective.hs, dist/build/Faker/Provider/Adjective.o, dist/build/Faker/Provider/Adjective.dyn_o )

src/Faker/Provider/Adjective.hs:19:17: error:
    • Couldn't match expected type ‘aeson-2.0.2.0:Data.Aeson.Key.Key’
                  with actual type ‘Text’
    • In the second argument of ‘(.:)’, namely ‘(getLocale settings)’
      In a stmt of a 'do' block: en <- obj .: (getLocale settings)
      In the expression:
        do en <- obj .: (getLocale settings)
           faker <- en .: "faker"
           adjective <- faker .: "adjective"
           pure adjective
   |
19 |   en <- obj .: (getLocale settings)
   |                 ^^^^^^^^^^^^^^^^^^

src/Faker/Provider/Adjective.hs:29:26: error:
    • Couldn't match expected type ‘aeson-2.0.2.0:Data.Aeson.Key.Key’
                  with actual type ‘Text’
    • In the second argument of ‘(.:?)’, namely ‘txt’
      In the first argument of ‘(.!=)’, namely ‘adjective .:? txt’
      In a stmt of a 'do' block: field <- adjective .:? txt .!= mempty
   |
29 |   field <- adjective .:? txt .!= mempty
   |                          ^^^

src/Faker/Provider/Adjective.hs:41:21: error:
    • Couldn't match expected type ‘aeson-2.0.2.0:Data.Aeson.Key.Key’
                  with actual type ‘Text’
    • In the second argument of ‘(.:)’, namely ‘x’
      In a stmt of a 'do' block: field <- a .: x
      In the expression:
        do field <- a .: x
           helper field xs
   |
41 |       field <- a .: x
   |                     ^

src/Faker/Provider/Adjective.hs:63:21: error:
    • Couldn't match expected type ‘aeson-2.0.2.0:Data.Aeson.Key.Key’
                  with actual type ‘Text’
    • In the second argument of ‘(.:)’, namely ‘x’
      In a stmt of a 'do' block: field <- a .: x
      In the expression:
        do field <- a .: x
           helper field xs
   |
63 |       field <- a .: x
   |                     ^

(This is just an example, many many modules fail with similar errors).

I think your best option might be to depend explicitly on aeson, and then you can put a suitable bound on (ideally updating code to support aeson-2). If you agree with this, I'd be happy to do the work and send a PR.

psibi commented 2 years ago

I think your best option might be to depend explicitly on aeson, and then you can put a suitable bound on (ideally updating code to support aeson-2). If you agree with this, I'd be happy to do the work and send a PR.

Thanks, that sounds good.