{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Plutarch.Builtin (
PDataNewtype (..),
) where
import Data.Kind (Type)
import GHC.Generics (Generic)
import Plutarch.Builtin.Data (PAsData, PData)
import Plutarch.Internal.Eq (PEq ((#==)))
import Plutarch.Internal.IsData (
PIsData,
pdataImpl,
pforgetData,
pfromData,
pfromDataImpl,
)
import Plutarch.Internal.Ord (POrd ((#<), (#<=)))
import Plutarch.Internal.Other (pto)
import Plutarch.Internal.PlutusType (
PInner,
PlutusType (pcon', pmatch'),
pmatch,
)
import Plutarch.Internal.Show (PShow (pshow'))
import Plutarch.Internal.Term (
S,
Term,
)
import Plutarch.Internal.TryFrom (PTryFrom)
import Plutarch.Unsafe (punsafeCoerce)
newtype PDataNewtype (a :: S -> Type) (s :: S) = PDataNewtype (Term s (PAsData a))
deriving stock
(
(forall x. PDataNewtype a s -> Rep (PDataNewtype a s) x)
-> (forall x. Rep (PDataNewtype a s) x -> PDataNewtype a s)
-> Generic (PDataNewtype a s)
forall x. Rep (PDataNewtype a s) x -> PDataNewtype a s
forall x. PDataNewtype a s -> Rep (PDataNewtype a s) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (a :: S -> Type) (s :: S) x.
Rep (PDataNewtype a s) x -> PDataNewtype a s
forall (a :: S -> Type) (s :: S) x.
PDataNewtype a s -> Rep (PDataNewtype a s) x
$cfrom :: forall (a :: S -> Type) (s :: S) x.
PDataNewtype a s -> Rep (PDataNewtype a s) x
from :: forall x. PDataNewtype a s -> Rep (PDataNewtype a s) x
$cto :: forall (a :: S -> Type) (s :: S) x.
Rep (PDataNewtype a s) x -> PDataNewtype a s
to :: forall x. Rep (PDataNewtype a s) x -> PDataNewtype a s
Generic
)
instance PlutusType (PDataNewtype a) where
type PInner (PDataNewtype a) = PData
pcon' :: forall (s :: S).
PDataNewtype a s -> Term s (PInner (PDataNewtype a))
pcon' (PDataNewtype Term s (PAsData a)
a) = Term s (PAsData a) -> Term s PData
forall (s :: S) (a :: S -> Type).
Term s (PAsData a) -> Term s PData
pforgetData Term s (PAsData a)
a
pmatch' :: forall (s :: S) (b :: S -> Type).
Term s (PInner (PDataNewtype a))
-> (PDataNewtype a s -> Term s b) -> Term s b
pmatch' Term s (PInner (PDataNewtype a))
x' PDataNewtype a s -> Term s b
f = PDataNewtype a s -> Term s b
f (Term s (PAsData a) -> PDataNewtype a s
forall (a :: S -> Type) (s :: S).
Term s (PAsData a) -> PDataNewtype a s
PDataNewtype (Term s (PInner (PDataNewtype a)) -> Term s (PAsData a)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce Term s (PInner (PDataNewtype a))
x'))
instance PIsData (PDataNewtype a) where
pfromDataImpl :: forall (s :: S).
Term s (PAsData (PDataNewtype a)) -> Term s (PDataNewtype a)
pfromDataImpl = Term s (PAsData (PDataNewtype a)) -> Term s (PDataNewtype a)
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce
pdataImpl :: forall (s :: S). Term s (PDataNewtype a) -> Term s PData
pdataImpl = Term s (PDataNewtype a) -> Term s PData
forall (b :: S -> Type) (a :: S -> Type) (s :: S).
Term s a -> Term s b
punsafeCoerce
instance PEq (PDataNewtype a) where
Term s (PDataNewtype a)
a #== :: forall (s :: S).
Term s (PDataNewtype a) -> Term s (PDataNewtype a) -> Term s PBool
#== Term s (PDataNewtype a)
b = Term s (PDataNewtype a) -> Term s (PInner (PDataNewtype a))
forall (s :: S) (a :: S -> Type). Term s a -> Term s (PInner a)
pto Term s (PDataNewtype a)
a Term s (PInner (PDataNewtype a))
-> Term s (PInner (PDataNewtype a)) -> Term s PBool
forall (s :: S).
Term s (PInner (PDataNewtype a))
-> Term s (PInner (PDataNewtype a)) -> Term s PBool
forall (t :: S -> Type) (s :: S).
PEq t =>
Term s t -> Term s t -> Term s PBool
#== Term s (PDataNewtype a) -> Term s (PInner (PDataNewtype a))
forall (s :: S) (a :: S -> Type). Term s a -> Term s (PInner a)
pto Term s (PDataNewtype a)
b
instance (PIsData a, POrd a) => POrd (PDataNewtype a) where
{-# INLINEABLE (#<=) #-}
Term s (PDataNewtype a)
a #<= :: forall (s :: S).
Term s (PDataNewtype a) -> Term s (PDataNewtype a) -> Term s PBool
#<= Term s (PDataNewtype a)
b =
Term s (PDataNewtype a)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term s (PDataNewtype a)
a ((PDataNewtype a s -> Term s PBool) -> Term s PBool)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall a b. (a -> b) -> a -> b
$ \(PDataNewtype Term s (PAsData a)
a') ->
Term s (PDataNewtype a)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term s (PDataNewtype a)
b ((PDataNewtype a s -> Term s PBool) -> Term s PBool)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall a b. (a -> b) -> a -> b
$ \(PDataNewtype Term s (PAsData a)
b') ->
Term s (PAsData a) -> Term s a
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s (PAsData a)
a' Term s a -> Term s a -> Term s PBool
forall (s :: S). Term s a -> Term s a -> Term s PBool
forall (t :: S -> Type) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
#<= Term s (PAsData a) -> Term s a
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s (PAsData a)
b'
{-# INLINEABLE (#<) #-}
Term s (PDataNewtype a)
a #< :: forall (s :: S).
Term s (PDataNewtype a) -> Term s (PDataNewtype a) -> Term s PBool
#< Term s (PDataNewtype a)
b =
Term s (PDataNewtype a)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term s (PDataNewtype a)
a ((PDataNewtype a s -> Term s PBool) -> Term s PBool)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall a b. (a -> b) -> a -> b
$ \(PDataNewtype Term s (PAsData a)
a') ->
Term s (PDataNewtype a)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term s (PDataNewtype a)
b ((PDataNewtype a s -> Term s PBool) -> Term s PBool)
-> (PDataNewtype a s -> Term s PBool) -> Term s PBool
forall a b. (a -> b) -> a -> b
$ \(PDataNewtype Term s (PAsData a)
b') ->
Term s (PAsData a) -> Term s a
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s (PAsData a)
a' Term s a -> Term s a -> Term s PBool
forall (s :: S). Term s a -> Term s a -> Term s PBool
forall (t :: S -> Type) (s :: S).
POrd t =>
Term s t -> Term s t -> Term s PBool
#< Term s (PAsData a) -> Term s a
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s (PAsData a)
b'
instance (PIsData a, PShow a) => PShow (PDataNewtype a) where
pshow' :: forall (s :: S). Bool -> Term s (PDataNewtype a) -> Term s PString
pshow' Bool
x Term s (PDataNewtype a)
t =
Term s (PDataNewtype a)
-> (PDataNewtype a s -> Term s PString) -> Term s PString
forall (a :: S -> Type) (s :: S) (b :: S -> Type).
PlutusType a =>
Term s a -> (a s -> Term s b) -> Term s b
pmatch Term s (PDataNewtype a)
t \(PDataNewtype Term s (PAsData a)
t') -> Bool -> Term s a -> Term s PString
forall (s :: S). Bool -> Term s a -> Term s PString
forall (t :: S -> Type) (s :: S).
PShow t =>
Bool -> Term s t -> Term s PString
pshow' Bool
x (Term s a -> Term s PString) -> Term s a -> Term s PString
forall a b. (a -> b) -> a -> b
$ Term s (PAsData a) -> Term s a
forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData Term s (PAsData a)
t'
instance (PIsData a, PTryFrom PData (PAsData a)) => PTryFrom PData (PDataNewtype a)
instance PTryFrom PData (PAsData (PDataNewtype a))