records-edsl-0.1.0: records-edsl.cabal
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.38.3.
--
-- see: https://github.com/sol/hpack
name: records-edsl
version: 0.1.0
synopsis: Write less record boilerplate
description: Cut off your boilerplate, eschew boilers entirely, and replace them with
a small teapot perched atop a small but slightly foreboding volcano.
.
This package defines a small EDSL to define records.
.
Provides an eDSL for defining record data-types and a closed vessel in
which fluid (generally water) is heated worth of boilerplate.
.
Defining a record type in this eDSL rather than plain Haskell gets you:
.
- Records without clashing names
.
- Syntax to access fields on records without Hungarian-notation prefixes on
every field (via 'GHC.HasField' and 'Optics.LabelOptic')
.
- Declarative syntax for defining that a field has an external
representation you want to use for its, for example, @ ToJSON @, @ FromJSON @, or
@ ToSchema @
.
This is accomplished with the help of the excellent "witch" library.
.
- 'ToSchema' instances with per-field field descriptions as per your comment
on each field
.
- 'ToSchema' instances with per-type descriptions
.
The EDSL also lets you extend what instances you get. The 'Deriver' type
defines how instances are defined.
.
Example:
.
We *can* write:
.
> declareSchemaRecords deriveAll """
> record Test --field-prefix=test {
> foo :: Int,
> bar :: MyType via MyTypeJSONRepr,
> }
> """
.
But maybe you prefer:
.
> data Test = Test
> { testFoo :: Int
> , testBar :: MyType
> }
> deriving stock (Show, Generic, Eq)
> deriving (Arbitrary) via (GenericArbitraryU Test)
>
> instance O.ToSchema Test where
> declareNamedSchema _ = ...
> -- ... instance using 'foo' as 'Int' and 'bar' as 'MyTypeJSONRepr'
> -- converting 'bar' using @ 'from' @
> --
> -- I'm so allergic to writing this by hand that I can't even be
> -- bothered to put it into an example. Rest assured, it's annoying
> -- and easy to make mistakes with.
>
> instance O.ToJSON Test where
> toJSON _ = ...
> toEncoding _ = ...
> -- ... instance using 'foo' as 'Int' and 'bar' as 'MyTypeJSONRepr'
> -- converting 'bar' using @ 'from' @.
>
> instance O.FromJSON Test where
> parseJSON = ...
> -- ... instance parsing 'foo' as 'Int' and 'bar' as 'MyTypeJSONRepr'
> -- converting 'bar' using @ 'from' @
.
In actual examples the hand-written code is 8-10 times larger than
with the declarative syntax.
category: Records
author: Mike Ledger
maintainer: Mike Ledger <mike@quasimal.com>
license: MPL-2.0
license-file: LICENSE
build-type: Simple
source-repository head
type: git
location: https://gitlab.com/combobulate.systems/records-edsl.git
library
exposed-modules:
Records.EDSL
hs-source-dirs:
./
default-extensions:
AllowAmbiguousTypes
BangPatterns
BlockArguments
DataKinds
DeriveAnyClass
DerivingStrategies
DerivingVia
DuplicateRecordFields
ExplicitForAll
GADTs
ImportQualifiedPost
LambdaCase
MultiWayIf
MultilineStrings
NamedFieldPuns
NoImplicitPrelude
NoStarIsType
OverloadedLabels
OverloadedRecordDot
OverloadedStrings
PartialTypeSignatures
PatternSynonyms
PolyKinds
RequiredTypeArguments
ScopedTypeVariables
StrictData
TemplateHaskell
TemplateHaskellQuotes
TypeApplications
TypeFamilies
ViewPatterns
build-depends:
base <5
, records-edsl-core >=0.1.0 && <0.2
, records-edsl-deriving-aeson >=0.1.0 && <0.2
, records-edsl-deriving-openapi3 >=0.1.0 && <0.2
, records-edsl-deriving-optics >=0.1.0 && <0.2
, records-edsl-deriving-quickcheck >=0.1.0 && <0.2
default-language: GHC2024
test-suite tests
type: exitcode-stdio-1.0
main-is: spec.hs
other-modules:
Paths_records_edsl
hs-source-dirs:
tests
default-extensions:
AllowAmbiguousTypes
BangPatterns
BlockArguments
DataKinds
DeriveAnyClass
DerivingStrategies
DerivingVia
DuplicateRecordFields
ExplicitForAll
GADTs
ImportQualifiedPost
LambdaCase
MultiWayIf
MultilineStrings
NamedFieldPuns
NoImplicitPrelude
NoStarIsType
OverloadedLabels
OverloadedRecordDot
OverloadedStrings
PartialTypeSignatures
PatternSynonyms
PolyKinds
RequiredTypeArguments
ScopedTypeVariables
StrictData
TemplateHaskell
TemplateHaskellQuotes
TypeApplications
TypeFamilies
ViewPatterns
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
aeson
, base <5
, hspec
, openapi3
, optics
, records-edsl
, relude
, text
, time
, witch
default-language: GHC2024