[Haskell-cafe] Domain modeling

Tikhon Jelvis tikhon at jelv.is
Wed Jan 29 20:27:10 UTC 2020


On my projects at Target, I've had a good experience using
DuplicateRecordFields coupled with a library like overloaded-records or
generic-lens. This lets us define records that share field names without
needing to use prefixes or multiple modules, while still being able to
access and modify those fields easily thanks to the OverloadedLabels
extension.

With this approach, you get a lens for every single record field without
name conflicts. If you have a bunch of records with a field called id,
you'll be able to access them using #id as a lens without running into name
conflicts with other records *or* with normal identifiers (like the id
function). You can then access fields with `record ^. #fieldName`, set them
with the .~ operator and compose them with other lenses and traversals.

When we first out together a system like this I was worried that it would
break type inference and cause weird error messages, but it had not caused
*any* problems in practice. Haskell's records went from being a royal pain
to being at least as convenient as any other language I've used, and
sometimes more (eg when combined with traversals).

On Wed, Jan 29, 2020, 06:13 Jean Lopes <hawu.bnu at gmail.com> wrote:

> Hi!
>
> I'm trying to encode a domain which is full of simple records, and a lot
> of field name clashes.
>
> Here is a simple example, a.k.a. 1:1 with the domain-spec:
>
> data C001 {
>>   -- other stuff
>>   indMov :: Bool
>> }
>> data C170 {
>>   -- other stuff
>>  indMov :: Bool
>> }
>
>
> There is ~148 records with this field (indMov), all with the same meaning.
> What are my options to encode this in Haskell?
>
> - Prefix all record fields to avoid name clashes?
> - Use *DuplicateRecordFields*?
> - Typeclasses???
> - other options I am not aware of?
>
> which would you prefer? and why of course :)
>
> Thanks,
> Jean Lopes
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20200129/5696b506/attachment.html>


More information about the Haskell-Cafe mailing list