-
Notifications
You must be signed in to change notification settings - Fork 500
Open
Labels
Description
Problem
Writing PlutusTx.Eq instances by hand is tedious and error-prone. Unlike Haskell's deriving stock Eq, there's no automatic way to derive equality for Plutus types.
Example of current manual approach:
instance PlutusTx.Eq MyType where
{-# INLINEABLE (==) #-}
(Con1 a1 b1) == (Con1 a2 b2) = a1 == a2 && b1 == b2
(Con2 x1) == (Con2 x2) = x1 == x2
_ == _ = FalseThis pattern repeats across plutus-ledger-api and user code, adding boilerplate and potential for bugs.
Solution
Add a Template Haskell function to derive PlutusTx.Eq instances:
data MyType = Con1 Integer Bool | Con2 ByteString
PlutusTx.deriveEq ''MyTypeThe generated code should:
- Use structural equality matching GHC's stock deriving behavior
- Include
INLINEABLEpragmas for on-chain optimization - Support datatypes, newtypes, records, and phantom type parameters
Definition of Done
-
PlutusTx.deriveEqfunction implemented and exported - Tests covering: multi-constructor ADTs, newtypes, records, phantom types
- Manual
Eqinstances inplutus-ledger-apireplaced with derived versions - Documentation with usage examples
- Changelog entry added
Reactions are currently unavailable