Plutarch also provides sophisticated generic deriving support for completely custom types. In particular, you can easily derive PlutusType
for your own type:
import qualified GHC.Generics as GHC
import Generics.SOP
import Plutarch.Prelude
data MyType (a :: PType) (b :: PType) (s :: S)
= One (Term s a)
| Two (Term s b)
deriving stock (GHC.Generic)
deriving anyclass (Generic, PlutusType)
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 PIsDataReprInstances
. Check out: implementing PIsDataRepr
and friends
Currently, generic deriving supports the following typeclasses:
PlutusType
(Scott encoding only)PIsDataRepr