Skip to content

Commit

Permalink
Do not prefix record field names (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored Feb 26, 2024
1 parent e155bb3 commit bae0306
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions haskell-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ been maintained for that as things have evolved.
- [What I Wish I Knew When Learning Haskell](http://dev.stephendiehl.com/hask/)
- [Haskell For Web Developers](http://www.stephendiehl.com/posts/haskell_web.html)

## Do not prefix record fields

There was once a time when record field names needed to be unique, and so it was
conventional to prefix them with a constructor name:

```haskell
data StudentAssignmentReport =
StudentAssignmentReport
{ studentAssignmentReportId :: UUID
, studentAssignmentReportGrade :: Percentage
, studentAssignmentReportTitle :: Text
}
```

Thanks to `NoFieldSelectors`, `DuplicateRecordFields`, and `OverloadedRecordDot`,
it does not matter whether a record field has the same name as anything else, and
so the prefixed field style is no longer useful. Such names should be shortened:

```haskell
data StudentAssignmentReport =
StudentAssignmentReport
{ id :: UUID
, grade :: Percentage
, title :: Text
}
```

## Existentials

Why / when you want to use them:
Expand Down
3 changes: 3 additions & 0 deletions haskell-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,14 @@ Sort your exports, unless the order matters in your desired Haddock output.
- DeriveAnyClass
- DerivingStrategies
- DerivingVia
- DuplicateRecordFields
- GADTs
- LambdaCase
- NoFieldSelectors
- NoImplicitPrelude
- NoMonomorphismRestriction
- NoPostfixOperators
- OverloadedRecordDot
- OverloadedStrings
- QuasiQuotes
- TypeFamilies
Expand Down

0 comments on commit bae0306

Please sign in to comment.