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

  • Home
  • SEARCH
  • 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 8676727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:16:16+00:00 2026-06-12T20:16:16+00:00

In Haskell, when defining a data type you can choose to automatically derive some

  • 0

In Haskell, when defining a data type you can choose to automatically derive
some instances, but can I defer the automatic deriving, perhaps even put it in
another library?

Here is an example:

Automatic deriving in Haskell is a real time saver!

module MoneyModule where

data Money = Money Int
  deriving Show

Now I wish to use the MoneyModule, but I also want a Read instance for Money:

module ExternalModule where

instance Read Money where
  read = error "Can't this be done automatically instead?"

But I would really have preferred for it to be derived automatically, which I know ghc could have done if only the MoneyModule author had auto-derived the Read instance.


I know that:

  • It’s better to fix the problem in the actual MoneyModule by patching it with the missing instance.
  • That it’s considered bad to have orphan instances. Instance declarations
    are preferably put in the module where either the type class or the data
    type was defined.

In my case I can’t follow best practices since the type class is unrelated
to the data type. I doubt that the type class module nor the data type module
wants to hold the instance, so therefore I’m creating a third library because in some
applications you need the instance declaration.

  • 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-12T20:16:17+00:00Added an answer on June 12, 2026 at 8:16 pm

    GHC has the StandaloneDeriving extension, with that, you can

    {-# LANGUAGE StandaloneDeriving #-}
    import MoneyModule
    
    deriving instance Read Money
    

    derive instances for many classes.

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

Sidebar

Related Questions

Can 2 or more equations defining a function in Haskell share the same where
Does haskell-mode or some alternative package offer something akin to the wonderful inferior-haskell-type inside
In Haskell, I can check a function's type in ghci by using :t :
In Haskell, I am having some problems defining functions because the types of my
Haskell's type safety is second to none only to dependently-typed languages. But there is
Haskell's Text.JSON library uses an abstract data type called Result, it's basically their form
I am a newbie in Haskell and have some problem of defining a function
Defining infinite list in Haskell: [1,1..] => [1,1,1,..] Or, the circular way: lst=1:lst Is
Haskell provides the feature something like f = f1 . f2 How can I
In Haskell, how can I generate Fibonacci numbers based on the property that the

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.