imports

module Plutarch.Docs.DerivingGenerics (PMyType (..)) where
import Plutarch.Prelude

Deriving typeclasses with generics

Plutarch also provides sophisticated generic deriving support for completely custom types. In particular, you can easily derive PlutusType for your own type:

data PMyType (a :: S -> Type) (b :: S -> Type) (s :: S)
  = POne (Term s a)
  | PTwo (Term s b)
  deriving stock Generic
  deriving anyclass PlutusType
instance DerivePlutusType (PMyType a b) where type DPTStrat _ = PlutusTypeScott

Note: This requires the generics-sop package.

This will use a Scott encoding representation for MyType, which is typically what you want. If you want to use data encoding representation instead in your PlutusType instance - you should derive it using PlutusTypeData. Check out: implementing PIsDataRepr and friends

Currently, generic deriving supports the following typeclasses: