aeson-dependent-sum: JSON encoding/decoding for dependent-sum

[ data, dependent-types, gpl, json, library ] [ Propose Tags ] [ Report a vulnerability ]

Newtype wrappers around Data.Dependent.Sum.DSum, for use with -XDerivingVia. These wrappers are helpful when parsing JSON objects where certain keys determine the type of the deserialised value.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1
Change log CHANGELOG.md
Dependencies aeson (>=2.0 && <2.2), base (>=4.9 && <4.18), constraints-extras (>=0.3.2.1 && <0.4), dependent-sum (>=0.7.1.0 && <0.8), some (>=1.0.0.3 && <1.1), vector (>=0.12.3.1 && <0.14) [details]
Tested with ghc ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.4 || ==9.4.1
License GPL-3.0-or-later
Copyright (c) 2022 Jack Kelly
Author Jack Kelly
Maintainer jack@jackkelly.name
Category Data, Dependent Types, JSON
Home page https://sr.ht/~jack/aeson-dependent-sum
Bug tracker https://todo.sr.ht/~jack/aeson-dependent-sum
Source repo head: git clone https://git.sr.ht/~jack/aeson-dependent-sum
Uploaded by jack at 2022-08-27T10:40:29Z
Distributions
Downloads 164 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-08-27 [all 1 reports]

Readme for aeson-dependent-sum-0.1.0.1

[back to package description]

aeson-dependent-sum

builds.sr.ht status GPLv3

If you need to (de)serialise JSON from/to a dependent sum (from the dependent-sum package), this library provides newtype wrappers which you can use with the -XDerivingVia language extension. You might want to do this if:

  • You want to be work with a real value representing the sum's "tag"; or
  • You want to take advantage of the f parameter provided by DSum.

Example

data CharacterClass a where
  Fighter :: CharacterClass Fighter
  Rogue :: CharacterClass Rogue
  Wizard :: CharacterClass Wizard

-- From the "constraints-extras" package:
$(deriveArgDict ''CharacterClass)
-- From the "dependent-sum-template" package. Not required, but useful:
$(deriveGShow ''CharacterClass)
$(deriveGEq ''CharacterClass)
$(deriveGCompare ''CharacterClass)

-- The derived `FromJSON`/`ToJSON` instances work on JSON objects like this:
-- {
--   "class": "fighter", -- or "rogue", or "wizard"
--   "data": { ... } -- the exact fields differ depending on the value at "class".
-- }
newtype Character = Character (DSum CharacterClass Identity)
  deriving (FromJSON, ToJSON)
  via (TaggedObject "Character" "class" "data" CharacterClass Identity)