Skip to content

Add attached derive clauses to data and newtype declarations#4594

Draft
i-am-the-slime wants to merge 1 commit intopurescript:masterfrom
i-am-the-slime:attached-derive-clauses
Draft

Add attached derive clauses to data and newtype declarations#4594
i-am-the-slime wants to merge 1 commit intopurescript:masterfrom
i-am-the-slime:attached-derive-clauses

Conversation

@i-am-the-slime
Copy link
Copy Markdown
Contributor

@i-am-the-slime i-am-the-slime commented Apr 19, 2026

Summary

Adds derive (Eq, Ord) clauses directly on data/newtype declarations:

data Colour = Red | Green | Blue
  derive (Eq, Ord)

newtype Name = Name String
  derive (Eq, Ord)

data Box a = Empty | Full a
  derive (Functor)

Multiple classes per clause, free mixing with standalone derive instance. Automatically infers correct type application for higher-kinded classes (e.g. Functor).

This is a reduced version of #4592, scoping out derive newtype and derive via to keep the diff small (11 files, 178 lines).

How it works

  1. New CST types (DeriveClass, DeriveClause) and grammar rules
  2. CST-to-AST conversion emits a temporary DeriveClauseDeclaration per class
  3. TypeClasses.hs desugars each into a TypeInstanceDeclaration with DerivedInstance body (the same node derive instance produces) and hands it to the existing handler

Adds Haskell-style derive clauses directly on data/newtype declarations:

  data Color = Red | Green | Blue
    derive (Eq, Ord)

  newtype Name = Name String
    derive newtype (Eq, Show)

Multiple classes per clause, multiple clauses per type, and free mixing
with standalone derive instance syntax. Automatically infers the correct
type application for higher-kinded classes like Functor.
@i-am-the-slime i-am-the-slime force-pushed the attached-derive-clauses branch from 4d36c00 to 86f4961 Compare April 19, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant