derive-has-field: Derive HasField instances with Template Haskell

[ library, mit, template-haskell ] [ Propose Tags ] [ Report a vulnerability ]

A Template Haskell function to derive HasField instances to utilize OverloadedRecordDot more effectively.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1.0, 0.0.1.1, 0.0.1.2, 0.0.1.3, 0.0.1.4, 0.0.1.5, 0.1.0.0
Dependencies base (>=4.7 && <5), template-haskell (>=2.5 && <2.20), th-abstraction (>0.4 && <0.7) [details]
License MIT
Copyright Barry Moore II
Author Barry Moore II
Maintainer chiroptical@gmail.com
Revised Revision 1 made by chiroptical at 2024-11-12T15:02:33Z
Home page https://github.com/chiroptical/snail#readme
Bug tracker https://github.com/chiroptical/snail/issues
Source repo head: git clone https://github.com/chiroptical/snail
Uploaded by chiroptical at 2023-09-26T22:06:51Z
Distributions
Downloads 241 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-09-26 [all 1 reports]

Readme for derive-has-field-0.0.1.0

[back to package description]

Derive HasField instances

The OverloadedRecordDot syntax is surprisingly nice. I really enjoy writing code with this extension and I was originally hesistant.

Persistent has a really nice feature where it will automatically remove prefixes from models. Given a model like,

BankAccount
  accountNumber String

You would normally reference this field as bankAccountAccountNumber. However, with overloaded record dot you can write bankAccount.accountNumber which is much nicer.

At work, I really wanted this for every record. With this library, I can write,

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}

import DeriveHasField

data BankAccount =
  BankAccount
    { bankAccountAccountNumber :: String
    }

deriveHasFieldWith (dropPrefix "bankAccount") ''BankAccount