From ed58c5cfada5af586a2905c4b822988aa6859919 Mon Sep 17 00:00:00 2001 From: Alice BRENON <alice.brenon@ens-lyon.fr> Date: Fri, 22 Dec 2023 14:28:35 +0100 Subject: [PATCH] Directly implement ToJSON on @ instead of an intermediate ToJSONObject => ToJSON to avoid confusing the compiler --- lib/GEODE/Metadata/Types.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/GEODE/Metadata/Types.hs b/lib/GEODE/Metadata/Types.hs index caeabec..881168a 100644 --- a/lib/GEODE/Metadata/Types.hs +++ b/lib/GEODE/Metadata/Types.hs @@ -35,9 +35,10 @@ class ToJSONObject a where toJSONObject :: a -> Object toJSONPairs :: a -> Series -instance {-# OVERLAPPABLE #-} ToJSONObject a => ToJSON a where - toJSON = Object . toJSONObject - toEncoding = pairs . toJSONPairs +instance {-# OVERLAPPABLE #-} (ToJSONObject a, ToJSONObject b) => + ToJSON (a @ b) where + toJSON (a :@: b) = Object $ toJSONObject a `Object.union` toJSONObject b + toEncoding (a :@: b) = pairs $ toJSONPairs a <> toJSONPairs b instance {-# OVERLAPPABLE #-} (FromJSON a, FromJSON b) => FromJSON (a @ b) where parseJSON o = (:@:) <$> parseJSON o <*> parseJSON o -- GitLab