Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6214293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:51:05+00:00 2026-05-24T06:51:05+00:00

I have two data types, which are used for hastache templates. It makes sense

  • 0

I have two data types, which are used for hastache templates. It makes sense in my code to have two different types, both with a field named “name”. This, of course, causes a conflict. It seems that there’s a mechanism to disambiguate any calls to “name”, but the actual definition causes problems. Is there any workaround, say letting the record field name be qualified?

data DeviceArray = DeviceArray
    { name :: String,
      bytes :: Int }
    deriving (Eq, Show, Data, Typeable)

data TemplateParams = TemplateParams
    { arrays :: [DeviceArray],
      input :: DeviceArray }
    deriving (Eq, Show, Data, Typeable)

data MakefileParams = MakefileParams
    { name :: String }
    deriving (Eq, Show, Data, Typeable)

i.e. if the fields are now used in code, they will be “DeviceArray.name” and “MakefileParams.name”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:51:05+00:00Added an answer on May 24, 2026 at 6:51 am

    As already noted, this isn’t directly possible, but I’d like to say a couple things about proposed solutions:

    If the two fields are clearly distinct, you’ll want to always know which you’re using anyway. By “clearly distinct” here I mean that there would never be a circumstance where it would make sense to do the same thing with either field. Given this, excess disambiguity isn’t really unwelcome, so you’d want either qualified imports as the standard approach, or the field disambiguation extension if that’s more to your taste. Or, as a very simplistic (and slightly ugly) option, just manually prefix the fields, e.g. deviceArrayName instead of just name.

    If the two fields are in some sense the same thing, it makes sense to be able to treat them in a homogeneous way; ideally you could write a function polymorphic in choice of name field. In this case, one option is using a type class for “named things”, with functions that let you access the name field on any appropriate type. A major downside here, besides a proliferation of trivial type constraints and possible headaches from the Dreaded Monomorphism Restriction, is that you also lose the ability to use the record syntax, which begins to defeat the whole point.

    The other major option for similar fields, which I didn’t see suggested yet, is to extract the name field out into a single parameterized type, e.g. data Named a = Named { name :: String, item :: a }. GHC itself uses this approach for source locations in syntax trees, and while it doesn’t use record syntax the idea is the same. The downside here is that if you have a Named DeviceArray, accessing the bytes field now requires going through two layers of records. If you want to update the bytes field with a function, you’re stuck with something like this:

    addBytes b na = na { item = (item na) { bytes = b + bytes (item na) } }
    

    Ugh. There are ways to mitigate the issue a bit, but they’re still not idea, to my mind. Cases like this are why I don’t like record syntax in general. So, as a final option, some Template Haskell magic and the fclabels package:

    {-# LANGUAGE TemplateHaskell #-}
    
    import Control.Category
    import Data.Record.Label
    
    data Named a = Named 
        { _name :: String, 
          _namedItem :: a }
        deriving (Eq, Show, Data, Typeable)
    
    data DeviceArray = DeviceArray { _bytes :: Int }
        deriving (Eq, Show, Data, Typeable)
    
    data MakefileParams = MakefileParams { _makefileParams :: [MakeParam] }
        deriving (Eq, Show, Data, Typeable)
    
    data MakeParam = MakeParam { paramText :: String }
        deriving (Eq, Show, Data, Typeable)
    
    $(mkLabels [''Named, ''DeviceArray, ''MakefileParams, ''MakeParam])
    

    Don’t mind the MakeParam business, I just needed a field on there to do something with. Anyway, now you can modify fields like this:

    addBytes b = modL (namedItem >>> bytes) (b +)
    nubParams = modL (namedItem >>> makefileParams) nub
    

    You could also name bytes something like bytesInternal and then export an accessor bytes = namedItem >>> bytesInternal if you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two mdi applications, both of which retrieve their data from the same
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two projects, the DLL project which has all my logic and data
I have a two-dimensional array (of Strings) which make up my data table (of
I have two processes one will query other for data.There will be huge amount
I have two files (f1 and f2) containing some text (or binary data). How
I have a two dimensional array that I need to load data into. I
I have an app that will have entries of both varchar(max) and varbinary(max) data
I have two different collections: List<int> IEnumerable<IDataRecord> The first contains a list of primary
I have two resources in my XAML which represent a Star and a Half

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.