$OpenBSD$

SPDX-License-Identifier: BSD-3-Clause

Add the KeyMap Unzip instance with correct instance ordering for GHC
9.14+ compatibility. semialign 1.4 makes Unzip a superclass of
Semialign, which requires the instance order: Unzip -> Semialign ->
Align -> Zip -> ZipWithIndex -> SemialignWithIndex. GHC 9.14 checks
superclass constraints at instance declaration time.

Index: src/Data/Aeson/KeyMap.hs
--- src/Data/Aeson/KeyMap.hs.orig
+++ src/Data/Aeson/KeyMap.hs
@@ -101,6 +101,8 @@
 import Prelude (Functor(fmap), Monad(..))
 import Prelude (Show, showsPrec, showParen, shows, showString)
 
+import Prelude (fst, snd)
+
 import Control.Applicative (Applicative)
 import Control.DeepSeq (NFData(..))
 import Data.Aeson.Key (Key)
@@ -690,21 +692,28 @@
 -- semialign
 -------------------------------------------------------------------------------
 
+-- Unzip must come first: Semialign depends on Unzip in semialign >= 1.3.
+instance SA.Unzip KeyMap where
+    unzip (KeyMap m) = (KeyMap (fmap fst m), KeyMap (fmap snd m))
+
+-- Semialign depends on Unzip; Zip depends on Semialign.
+instance SA.Semialign KeyMap where
+    alignWith = alignWith
+
+instance SA.Align KeyMap where
+    nil = empty
+
 instance SA.Zip KeyMap where
     zipWith = intersectionWith
 
+-- ZipWithIndex depends on Zip.
 instance SAI.ZipWithIndex Key KeyMap where
     izipWith = intersectionWithKey
 
-instance SA.Semialign KeyMap where
-    alignWith = alignWith
-
+-- SemialignWithIndex depends on Semialign.
 instance SAI.SemialignWithIndex Key KeyMap where
     ialignWith = alignWithKey
 
-instance SA.Align KeyMap where
-    nil = empty
-
 -------------------------------------------------------------------------------
 -- witherable
 -------------------------------------------------------------------------------
