Skip to content

Commit

Permalink
Merge pull request #1105 from haskell/gnd-key
Browse files Browse the repository at this point in the history
Use GND to derive Key instances
  • Loading branch information
phadej authored Jun 9, 2024
2 parents 16776c4 + 1a666fe commit 27517f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 2 additions & 3 deletions aeson.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cabal-version: 2.2
name: aeson
version: 2.2.2.0
x-revision: 1
version: 2.2.3.0
license: BSD-3-Clause
license-file: LICENSE
category: Text, Web, JSON
Expand Down Expand Up @@ -116,7 +115,7 @@ library
, character-ps ^>=0.1
, data-fix ^>=0.3.2
, dlist ^>=1.0
, hashable ^>=1.4.2.0
, hashable ^>=1.4.6.0
, indexed-traversable ^>=0.1.2
, integer-conversion ^>=0.1
, integer-logarithms ^>=1.0.3.1
Expand Down
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ allow-newer: hermes-json:attoparsec-iso8601

-- packages: https://hackage.haskell.org/package/libperf-0.1/candidate/libperf-0.1.tar.gz
-- packages: https://hackage.haskell.org/package/tasty-perfbench-0.1/candidate/tasty-perfbench-0.1.tar.gz

-- constraints: aeson -ordered-keymap
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
For the latest version of this document, please see [https://github.com/haskell/aeson/blob/master/changelog.md](https://github.com/haskell/aeson/blob/master/changelog.md).

### 2.2.3.0

* Support `hashable-1.4.6.0`.

### 2.2.2.0

* Support GHC-8.6.5...9.10.1
Expand Down
14 changes: 9 additions & 5 deletions src/Data/Aeson/Key.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskellQuotes #-}

-- |
Expand Down Expand Up @@ -39,7 +42,7 @@ import qualified Language.Haskell.TH.Syntax as TH
import qualified Test.QuickCheck as QC

newtype Key = Key { unKey :: Text }
deriving (Eq, Ord, Typeable, Data)
deriving (Typeable, Data)

fromString :: String -> Key
fromString = Key . T.pack
Expand All @@ -58,7 +61,7 @@ toText = unKey
--
-- Using 'coercing' we can make more efficient implementations
-- when 'Key' is backed up by 'Text' without exposing internals.
--
--
coercionToText :: Maybe (Coercion Key Text)
coercionToText = Just Coercion
{-# INLINE coercionToText #-}
Expand All @@ -79,13 +82,14 @@ instance Read Key where
readPrec = fromString <$> readPrec

instance Show Key where
showsPrec d (Key k) = showsPrec d k
showsPrec d (Key k) = showsPrec d k

instance Data.String.IsString Key where
fromString = fromString

instance Hashable Key where
hashWithSalt salt (Key k) = hashWithSalt salt k
deriving newtype instance Eq Key
deriving newtype instance Ord Key
deriving newtype instance Hashable Key

instance NFData Key where
rnf (Key k) = rnf k
Expand Down

0 comments on commit 27517f0

Please sign in to comment.