Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Latest commit

 

History

History
24 lines (17 loc) · 1.29 KB

Deriving with generics.md

File metadata and controls

24 lines (17 loc) · 1.29 KB

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:

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: