simmsb / calamity

A library for writing discord bots in haskell
https://hackage.haskell.org/package/calamity
MIT License
109 stars 11 forks source link

aeson 2.2 support #67

Closed Miezhiko closed 3 months ago

Miezhiko commented 3 months ago

not sure how to fix this code after aeson 2.2 changes, current cabal limits <2.2 but for better compatibility with other things I want it to build with aeson 2.2.1 so I need little help

(.?=) :: (Aeson.ToJSON v, Aeson.KeyValue kv) => Aeson.Key -> Maybe v -> Maybe kv
k .?= Just v = Just (k Aeson..= v)
_ .?= Nothing = Nothing

(.=) :: (Aeson.ToJSON v, Aeson.KeyValue kv) => Aeson.Key -> v -> Maybe kv
k .= v = Just (k Aeson..= v)

class CalamityToJSON' a where
  toPairs :: Aeson.KeyValue kv => a -> [Maybe kv]

newtype CalamityToJSON a = CalamityToJSON a

instance CalamityToJSON' a => Aeson.ToJSON (CalamityToJSON a) where
  toJSON (CalamityToJSON x) = Aeson.object . catMaybes . toPairs $ x
  toEncoding (CalamityToJSON x) = Aeson.pairs . mconcat . catMaybes . toPairs $ x

it gives

• Expecting one more argument to ‘Aeson.KeyValue kv’ Expected a constraint, but ‘Aeson.KeyValue kv’ has kind ‘* -> Constraint’ • In the type signature: toPairs :: Aeson.KeyValue kv => a -> [Maybe kv] In the class declaration for ‘CalamityToJSON'’ | | toPairs :: Aeson.KeyValue kv => a -> [Maybe kv]

DrewFenwick commented 3 months ago

I directed @Miezhiko to convert Aeson.KeyValue kv to Aeson.KeyValue e kv in the functional programming discord. That seemed to fix this error.

Miezhiko commented 3 months ago

this change will break 2.1 compat most likely, issue is actual on whether it's worthwhile to use CPP to maintain compatibility or whether to just drop support for aeson 2.1