Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.51 KB

Deriving with generics.md

File metadata and controls

40 lines (31 loc) · 1.51 KB
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 :: 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: