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 9202901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:21:29+00:00 2026-06-17T23:21:29+00:00

What I am talking about is that it is not possible to define: data

  • 0

What I am talking about is that it is not possible to define:

data A = A {name :: String}
data B = B {name :: String}

I know that the GHC just desugars this to plain functions and the idiomatic way to solve this would be:

data A = A {aName :: String}
data B = B {bName :: String}

class Name a where
  name :: a -> String

instance Name A where
  name = aName

instance Name B where
  name = bName

After having written this out I don’t like it that much … couldn’t this typeclassing be part of the desugaring process?


The thought came to me when I was writing some Aeson JSON parsing. Where it would have been too easy to just derive the FromJSON instances for every data type I had to write everything out by hand (currently >1k lines and counting).
Having names like name or simply value in a data record is not that uncommon.

http://www.haskell.org/haskellwiki/Performance/Overloading mentions that function overloading introduces some runtime overhead. But I actually don’t see why the compiler wouldn’t be able to resolve this at compile time and give them different names internally.

This SO question from 2012 more or less states historical reasons and points to a mail thread from 2006. Has anything changed recently?

Even if there would be some runtime overhead most people wouldn’t mind cause most code hardly is performance critical.

Is there some hidden language extension that actually allows this? Again I am not sure … but I think Idris actually does this?

  • 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-06-17T23:21:30+00:00Added an answer on June 17, 2026 at 11:21 pm

    Using the record syntax

    data A { name :: String }
    

    implicitly defines a function

    name :: A -> String
    

    If define both A and B with a { name :: String }, we have conflicting type definitions for name:

    name :: A -> String
    name :: B -> String
    

    It’s not clear how your proposed implicit type classes would work because if we define two types

    data A { name :: String }
    data B { name :: Text }
    

    then we have just shifted the problem to conflicting type class definitions:

    class Has'name a where
         name :: a -> String
    
    class Has'name a where
         name :: a -> Text
    

    In principle this could be resolved one way or another, but this is just one of several tricky conflicting desirable properties for records. When Haskell was defined, it was decided that it was better to have simple if limited support rather than to try to design something more ambitious and complicated. Several improvements to records have been discussed at various times and there are perennial discussions, e.g. this Haskell Cafe thread. Perhaps something will be worked out for Haskell Prime.

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

Sidebar

Related Questions

First of all, I want to be clear that I'm not talking about defining
What I'm talking about is: Is it possible that under certain circumstances the CPU
I'm talking about these . Yeah, I know they are intended to show that
I know there are a lot of threads talking about this and believe me
This is most likely not possible, but I'm just asking this to check... I'm
We are talking about using the Adapter Pattern for logging. I'm not sure that
I was wondering what language to use when talking about a function that takes
Im talking about performing a deep recursion for around 5+ mins, something that you
I'm talking about a detached object, that later I want to update with saveOrUpdate().
Yes, I am talking about Java 1.3 - I'm maintaining an application that for

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.