
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

I've been getting a lot of mileage from DuplicateRecordFields lately. You
just have to commit to not using labels as accessors. That is, no writing
`indMov x`. Instead, you have to write something like `myFunc C170{indMov}
= ...` (with NamedFieldPuns) or `myFunc C170{indMov=someBinder} = ...`.
On Wed, Jan 29, 2020 at 9:13 AM Jean Lopes
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.
-- -Andrew Thaddeus Martin

I've always been happy with the simplicity of using modules as namespaces
for this. Give each data type its own module, and import qualified to avoid
name clashes. If you're doing something specific to a single type, you can
import unqualified and not use the prefix. The only downside is that you
can't make a singe module re-exporting all the types, since you can't
re-export prefixed.
If this field has the same meaning in each data type, and you need to write
functions that are generic over all of them, go with a type class.
Cheers,
Erik
On Wed, 29 Jan 2020 at 15:13, Jean Lopes
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.

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
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.

Jean Lopes
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?
Is there some reason why they must be different types? data C = C001 {other_stuff:: Real, indMov:: Bool } | C170 {other_stuff…, indMov:: Bool } is the first thing that comes to mind. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk

The main reason to have distinct types is the "natural" hierarchy of the
records (it's a big tree), for example, the 'C' block is roughly as follows:
C001
- C100
- C101
- C105
- C110
- C111
- C112
- C113
- C114
- C115
- C116
- C120
- C130
- C140
- C141
- C160
- C165
- C170
- C171
- C172
- C173
- C174
- C175
- C176
- C177
- C178
- C179
- C180
- C185
- C190
- C191
- C195
- C197
- C300
- C310
- C320
- C321
- C330
- C350
- C370
- C380
- C390
- C400
- C405
- C410
- C420
- C425
- C430
- C460
- C465
- C470
- C480
- C490
- C495
- C500
- C510
- C590
- C591
- C595
- C597
- C600
- C601
- C610
- C690
- C700
- C790
- C791
- C800
- C810
- C815
- C850
- C860
- C870
- C880
- C890
C990
There is more blocks that form the whole document (or tree), Blocks: 0, B,
C, D, E, G, H, K, I, 9
The idea is to parse the document and implement manipulation functions to
edit the content and later export in other formats
On Thu, Jan 30, 2020 at 6:56 AM Jon Fairbairn
Jean Lopes
writes: 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?
Is there some reason why they must be different types?
data C = C001 {other_stuff:: Real, indMov:: Bool } | C170 {other_stuff…, indMov:: Bool }
is the first thing that comes to mind. -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
_______________________________________________ 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.
participants (5)
-
Andrew Martin
-
Erik Hesselink
-
Jean Lopes
-
Jon Fairbairn
-
Tikhon Jelvis