@@ -419,38 +419,28 @@ class FromJSONKey a where
419
419
default fromJSONKeyList :: FromJSON a => FromJSONKeyFunction [a ]
420
420
fromJSONKeyList = FromJSONKeyValue parseJSON
421
421
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
-
432
422
-- | This type is related to 'ToJSONKeyFunction'. If 'FromJSONKeyValue' is used in the
433
423
-- 'FromJSONKey' instance, then 'ToJSONKeyValue' should be used in the 'ToJSONKey'
434
424
-- instance. The other three data constructors for this type all correspond to
435
425
-- 'ToJSONKeyText'. Strictly speaking, 'FromJSONKeyTextParser' is more powerful than
436
426
-- 'FromJSONKeyText', which is in turn more powerful than 'FromJSONKeyCoerce'.
437
427
-- 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
442
432
-- ^ conversion from 'Text' that always succeeds
443
- | FromJSONKeyTextParser ! (Text -> Parser a )
433
+ FromJSONKeyTextParser :: ! (Text -> Parser a ) -> FromJSONKeyFunction a
444
434
-- ^ conversion from 'Text' that may fail
445
- | FromJSONKeyValue ! (Value -> Parser a )
435
+ FromJSONKeyValue :: ! (Value -> Parser a ) -> FromJSONKeyFunction a
446
436
-- ^ conversion for non-textual keys
447
437
448
438
-- | Only law abiding up to interpretation
449
439
instance 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)
454
444
455
445
-- | Construct 'FromJSONKeyFunction' for types coercible from 'Text'. This
456
446
-- conversion is still unsafe, as 'Hashable' and 'Eq' instances of @a@ should be
@@ -463,7 +453,7 @@ instance Functor FromJSONKeyFunction where
463
453
fromJSONKeyCoerce ::
464
454
Coercible Text a =>
465
455
FromJSONKeyFunction a
466
- fromJSONKeyCoerce = FromJSONKeyCoerce CoerceText
456
+ fromJSONKeyCoerce = FromJSONKeyCoerce
467
457
468
458
-- | Semantically the same as @coerceFromJSONKeyFunction = fmap coerce = coerce@.
469
459
--
@@ -473,10 +463,6 @@ coerceFromJSONKeyFunction ::
473
463
FromJSONKeyFunction a -> FromJSONKeyFunction b
474
464
coerceFromJSONKeyFunction = coerce
475
465
476
- {-# RULES
477
- "FromJSONKeyCoerce: fmap id" forall (x :: FromJSONKeyFunction a).
478
- fmap id x = x
479
- #-}
480
466
{-# RULES
481
467
"FromJSONKeyCoerce: fmap coerce" forall x .
482
468
fmap coerce x = coerceFromJSONKeyFunction x
@@ -1887,7 +1873,7 @@ instance FromJSON a => FromJSON (IntMap.IntMap a) where
1887
1873
1888
1874
instance (FromJSONKey k , Ord k ) => FromJSON1 (M. Map k ) where
1889
1875
liftParseJSON p _ = case fromJSONKey of
1890
- FromJSONKeyCoerce _ -> withObject " Map" $
1876
+ FromJSONKeyCoerce -> withObject " Map" $
1891
1877
fmap (H. foldrWithKey (M. insert . unsafeCoerce) M. empty) . H. traverseWithKey (\ k v -> p v <?> Key k)
1892
1878
FromJSONKeyText f -> withObject " Map" $
1893
1879
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
1967
1953
1968
1954
instance (FromJSONKey k , Eq k , Hashable k ) => FromJSON1 (H. HashMap k ) where
1969
1955
liftParseJSON p _ = case fromJSONKey of
1970
- FromJSONKeyCoerce _ -> withObject " HashMap ~Text" $
1956
+ FromJSONKeyCoerce -> withObject " HashMap ~Text" $
1971
1957
uc . H. traverseWithKey (\ k v -> p v <?> Key k)
1972
1958
FromJSONKeyText f -> withObject " HashMap" $
1973
1959
fmap (mapKey f) . H. traverseWithKey (\ k v -> p v <?> Key k)
0 commit comments