Skip to content

Commit

Permalink
Fix use of partial function by dropping support for ghc < 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfmpe committed Jan 13, 2025
1 parent 2c2823f commit dcb6953
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aeson-gadt-th.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ flag build-readme

library
exposed-modules: Data.Aeson.GADT.TH
build-depends: base >= 4.8 && < 4.21
build-depends: base >= 4.9 && < 4.21
, aeson >= 1.3 && < 2.3
, containers >= 0.5 && < 0.8
, dependent-sum >= 0.4 && < 0.8
Expand Down
7 changes: 4 additions & 3 deletions src/Data/Aeson/GADT/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import Control.Monad (forM, replicateM)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Writer (WriterT, runWriterT, tell)
import Data.Aeson (FromJSON(..), ToJSON(..))
import Data.List (group, intercalate, partition, sort)
import Data.List (intercalate, partition, sort)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Set (Set)
Expand Down Expand Up @@ -117,7 +118,7 @@ deriveToJSONGADTWithOptions opts n = do
topVars <- makeTopVars n
let n' = foldl (\c v -> AppT c (VarT v)) (ConT n) topVars
(matches, constraints') <- runWriterT (mapM (fmap pure . conMatchesToJSON opts topVars) cons)
let constraints = map head . group . sort $ constraints' -- This 'head' is safe because 'group' returns a list of non-empty lists
let constraints = map NonEmpty.head . NonEmpty.group . sort $ constraints'
impl <- funD 'toJSON
[ clause [] (normalB $ lamCaseE matches) []
]
Expand Down Expand Up @@ -149,7 +150,7 @@ deriveFromJSONGADTWithOptions opts n = do
topVars <- makeTopVars n
let n' = foldl (\c v -> AppT c (VarT v)) (ConT n) $ init topVars
(matches, constraints') <- runWriterT $ mapM (conMatchesParseJSON opts topVars [|_v'|]) cons
let constraints = map head . group . sort $ constraints' -- This 'head' is safe because 'group' returns a list of non-empty lists
let constraints = map NonEmpty.head . NonEmpty.group . sort $ constraints'
v <- newName "v"
parser <- funD 'parseJSON
[ clause [varP v] (normalB [e|
Expand Down

0 comments on commit dcb6953

Please sign in to comment.