@@ -419,38 +419,28 @@ class FromJSONKey a where
419419 default fromJSONKeyList :: FromJSON a => FromJSONKeyFunction [a ]
420420 fromJSONKeyList = FromJSONKeyValue parseJSON
421421
422- -- | With GHC 7.8+ we carry around @'Coercible' 'Text' a@ dictionary,
423- -- to give us an assurance that the program will not segfault.
424- -- Unfortunately we cannot enforce that the 'Eq' instances or the
425- -- 'Hashable' instances for 'Text' and @a@ agree.
426- --
427- -- At the moment this type is intentionally not exported. 'FromJSONKeyFunction'
428- -- can be inspected, but cannot be constructed.
429- data CoerceText a where
430- CoerceText :: Coercible Text a => CoerceText a
431-
432422-- | This type is related to 'ToJSONKeyFunction'. If 'FromJSONKeyValue' is used in the
433423-- 'FromJSONKey' instance, then 'ToJSONKeyValue' should be used in the 'ToJSONKey'
434424-- instance. The other three data constructors for this type all correspond to
435425-- 'ToJSONKeyText'. Strictly speaking, 'FromJSONKeyTextParser' is more powerful than
436426-- 'FromJSONKeyText', which is in turn more powerful than 'FromJSONKeyCoerce'.
437427-- For performance reasons, these exist as three options instead of one.
438- data FromJSONKeyFunction a
439- = FromJSONKeyCoerce ! ( CoerceText a )
440- -- ^ uses 'coerce' ('unsafeCoerce' in older GHCs)
441- | FromJSONKeyText ! (Text -> a )
428+ data FromJSONKeyFunction a where
429+ FromJSONKeyCoerce :: Coercible Text a => FromJSONKeyFunction a
430+ -- ^ uses 'coerce'
431+ FromJSONKeyText :: ! (Text -> a ) -> FromJSONKeyFunction a
442432 -- ^ conversion from 'Text' that always succeeds
443- | FromJSONKeyTextParser ! (Text -> Parser a )
433+ FromJSONKeyTextParser :: ! (Text -> Parser a ) -> FromJSONKeyFunction a
444434 -- ^ conversion from 'Text' that may fail
445- | FromJSONKeyValue ! (Value -> Parser a )
435+ FromJSONKeyValue :: ! (Value -> Parser a ) -> FromJSONKeyFunction a
446436 -- ^ conversion for non-textual keys
447437
448438-- | Only law abiding up to interpretation
449439instance Functor FromJSONKeyFunction where
450- fmap h ( FromJSONKeyCoerce CoerceText ) = FromJSONKeyText (h . coerce)
451- fmap h (FromJSONKeyText f) = FromJSONKeyText (h . f)
452- fmap h (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap h . f)
453- fmap h (FromJSONKeyValue f) = FromJSONKeyValue (fmap h . f)
440+ fmap h FromJSONKeyCoerce = FromJSONKeyText (h . coerce)
441+ fmap h (FromJSONKeyText f) = FromJSONKeyText (h . f)
442+ fmap h (FromJSONKeyTextParser f) = FromJSONKeyTextParser (fmap h . f)
443+ fmap h (FromJSONKeyValue f) = FromJSONKeyValue (fmap h . f)
454444
455445-- | Construct 'FromJSONKeyFunction' for types coercible from 'Text'. This
456446-- conversion is still unsafe, as 'Hashable' and 'Eq' instances of @a@ should be
@@ -463,7 +453,7 @@ instance Functor FromJSONKeyFunction where
463453fromJSONKeyCoerce ::
464454 Coercible Text a =>
465455 FromJSONKeyFunction a
466- fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
456+ fromJSONKeyCoerce = FromJSONKeyCoerce
467457
468458-- | Semantically the same as @coerceFromJSONKeyFunction = fmap coerce = coerce@.
469459--
@@ -473,10 +463,6 @@ coerceFromJSONKeyFunction ::
473463 FromJSONKeyFunction a -> FromJSONKeyFunction b
474464coerceFromJSONKeyFunction = coerce
475465
476- {-# RULES
477- "FromJSONKeyCoerce: fmap id" forall (x :: FromJSONKeyFunction a).
478- fmap id x = x
479- #-}
480466{-# RULES
481467 "FromJSONKeyCoerce: fmap coerce" forall x .
482468 fmap coerce x = coerceFromJSONKeyFunction x
@@ -1887,7 +1873,7 @@ instance FromJSON a => FromJSON (IntMap.IntMap a) where
18871873
18881874instance (FromJSONKey k , Ord k ) => FromJSON1 (M. Map k ) where
18891875 liftParseJSON p _ = case fromJSONKey of
1890- FromJSONKeyCoerce _ -> withObject " Map" $
1876+ FromJSONKeyCoerce -> withObject " Map" $
18911877 fmap (H. foldrWithKey (M. insert . unsafeCoerce) M. empty) . H. traverseWithKey (\ k v -> p v <?> Key k)
18921878 FromJSONKeyText f -> withObject " Map" $
18931879 fmap (H. foldrWithKey (M. insert . f) M. empty) . H. traverseWithKey (\ k v -> p v <?> Key k)
@@ -1967,7 +1953,7 @@ instance (Eq a, Hashable a, FromJSON a) => FromJSON (HashSet.HashSet a) where
19671953
19681954instance (FromJSONKey k , Eq k , Hashable k ) => FromJSON1 (H. HashMap k ) where
19691955 liftParseJSON p _ = case fromJSONKey of
1970- FromJSONKeyCoerce _ -> withObject " HashMap ~Text" $
1956+ FromJSONKeyCoerce -> withObject " HashMap ~Text" $
19711957 uc . H. traverseWithKey (\ k v -> p v <?> Key k)
19721958 FromJSONKeyText f -> withObject " HashMap" $
19731959 fmap (mapKey f) . H. traverseWithKey (\ k v -> p v <?> Key k)
0 commit comments