imports
module Plutarch.Docs.DerivingGenerics (PMyType (..)) where
import Plutarch.Prelude
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 :: PType) (b :: PType) (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:
PlutusType
(Scott encoding only)PEq
POrd
/PPartialOrd
PTryFrom
PShow
PIsData
PDataFields