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]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,
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
Category Template Haskell
Home page
Bug tracker
Source repo head: git clone
Uploaded by chiroptical at 2024-02-05T16:50:11Z
Distributions NixOS:
Downloads 32 total (22 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-

[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,

  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 =
    { bankAccountAccountNumber :: String

deriveHasFieldWith (dropPrefix "bankAccount") ''BankAccount