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

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

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


[Skip to Readme]

Downloads

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
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
Category Template Haskell
Home page https://github.com/chiroptical/derive-has-field#readme
Bug tracker https://github.com/chiroptical/derive-has-field/issues
Source repo head: git clone https://github.com/chiroptical/derive-has-field
Uploaded by chiroptical at 2024-10-15T17:39:41Z
Distributions
Downloads 140 total (26 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for derive-has-field-0.0.1.3

[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