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

[ library, mit, template-haskell ] [ Propose Tags ]

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
Dependencies base (>=4.7 && <5), template-haskell, th-abstraction (>0.4 && <0.7) [details]
License MIT
Copyright Barry Moore II
Author Barry Moore II
Maintainer chiroptical@gmail.com
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 54 total (10 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