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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:53:15+00:00 2026-05-17T02:53:15+00:00

Algebraic Data Types (ADTs) in Haskell can automatically become instances of some typeclasse s

  • 0

Algebraic Data Types (ADTs) in Haskell can automatically become instances of some typeclasses (like Show, Eq) by deriving from them.

data  Maybe a  =  Nothing | Just a
  deriving (Eq, Ord)

My question is, how does this deriving work, i.e. how does Haskell know how to implement the functions of the derived typeclass for the deriving ADT?

Also, why is deriving restricted to certain typeclasses only? Why can’t I write my own typeclass which can be derived?

  • 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-17T02:53:15+00:00Added an answer on May 17, 2026 at 2:53 am

    The short answer is, magic :-). This is to say that automatic deriving is baked into the Haskell spec, and every compiler can choose to implement it in its own way. There’s lots of work on how to make it extensible however.

    Derive is a tool for Haskell to let you write your own deriving mechanisms.

    GHC used to provide a derivable type class extension called Generic Classes, but it was rarely used, as it was somewhat weak.
    That has now been taken out, and work is ongoing to integrate a new generic deriving mechanism as described in this paper: http://www.dreixel.net/research/pdf/gdmh.pdf

    For more on this, see:

    • GHC wiki: http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/GenericDeriving
    • Haskell wiki: http://www.haskell.org/haskellwiki/Generics
    • Hackage: http://hackage.haskell.org/package/generic-deriving
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know haskell syntax, but I know some FP concepts (like algebraic data
I'm creating a library to allow OCaml/Haskell-like algebraic data types and pattern matching. The
Correct me if I'm wrong, but it seems like algebraic data types in Haskell
Imagine I have a recursive algebraic data type like this (Haskell syntax): data Expr
I have some algebraic data types A, B, and C each implements the class:
When dealing with sizeable algebraic data types in Haskell, there is a particular recursive
I would like to do an algebraic curve fit of 2D data points, but
I have the following algebraic data types: data Exp = Con Int | Var
The 'algebraic' expression for algebraic data types looks very suggestive to someone with a
In formal specifications based on abstract algebraic types and equational theory you use formulas

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.