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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:39:24+00:00 2026-05-23T16:39:24+00:00

The general question is which module structure is more convenient when adding instances for

  • 0

The general question is which module structure is more convenient when adding instances for existing objects? Which pros and cons there are?

Let’s say I want to add NFData instance for Seq type. I can place it in:

  • Data.Sequence.Extra (as the same thing is done in the vty package)
  • Data.Sequence.Instances.NFData (more precise)
  • Control.DeepSeq.Instances
  • Control.DeepSeq.Instances.Sequence

It’s the case when I don’t own neither the type class nor the data type. The other common situation is when I own a type type class and want to add instances for data type(s) from some “heavy” package from Hackage, like OpenGL. Let’s say the type class I designed is very light and has no direct relation to OpenGL. I don’t want my type class depend on “heavy” package, so I want to place OpenGL instances in a separate module (it’s my intuitive feeling, if you have other opinion, let’s discuss it). So, what this module should be:

  • MyClass.Instances.OpenGL
  • Graphics.Rendering.OpenGL.Extra (together with instances for other classes)
  • Graphics.Rendering.OpenGL.Instances.MyClass

What is more flexible solution? At some point OpenGL can be replaced with other library, or MyClass can be replaced too. Are there any subtle nuances?

Also, which scheme is better if choose MyClass.Instances variant:

  • MyClass.Class module for the class itself and basic instances and MyClass module reexports it (and maybe MyClass.Instances)
  • MyClass module for the class and basic instances, and MyClass.All reexports everything
  • MyClass module for the class and basic instances and no module for reexporting.
  • 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-23T16:39:24+00:00Added an answer on May 23, 2026 at 4:39 pm

    The usual process of deciding where to put an instance goes something like this:

    1. If you’re making a new data type and want an instance for an existing class:

      Put the instance in the same module as the data type.

    2. If you’re making a new type class and want to make instances for existing types.

      Put the instances in the same module as the type class.

    3. Both the type class and the data type already exist (your case).

      If the instance is sufficiently general, I’d contact the author of either the type class or the data type and try to convince them to add the instance in their package.

      Otherwise, create a newtype wrapper and write an instance for that.

      Only as a last resort consider making an orphan instance.

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

Sidebar

Related Questions

This is a more general question, but which has wider implications for a data
General javascript question here, which would also be good to know how(if possible) to
This is more a general question but my particular case involves a ruby/rails app
Sorry for the kind of general question. More details about what I want: I
This is a general question, so I won't name which site's API I am
This is a general question which will apply to any WPF control. What I
This is more of a general question i suppose... I am looking to start
I am stuck with a question which is stated below, Describe the general characteristics
general question is i like to build logger class that writes to single log
This is just a general question - I was sitting and waiting for a

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.