{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module PlutusCore.Builtin.HasConstant
( BuiltinError (..)
, throwNotAConstant
, HasConstant (..)
, HasConstantIn
, fromValueOf
, fromValue
) where
import PlutusCore.Builtin.Result
import PlutusCore.Core
import PlutusCore.Name.Unique
import Universe
class HasConstant term where
asConstant :: term -> Either BuiltinError (Some (ValueOf (UniOf term)))
fromConstant :: Some (ValueOf (UniOf term)) -> term
type HasConstantIn uni term = (UniOf term ~ uni, HasConstant term)
fromValueOf :: forall a term. HasConstant term => UniOf term (Esc a) -> a -> term
fromValueOf :: forall a term. HasConstant term => UniOf term (Esc a) -> a -> term
fromValueOf UniOf term (Esc a)
uni = Some (ValueOf (UniOf term)) -> term
forall term.
HasConstant term =>
Some (ValueOf (UniOf term)) -> term
fromConstant (Some (ValueOf (UniOf term)) -> term)
-> (a -> Some (ValueOf (UniOf term))) -> a -> term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UniOf term (Esc a) -> a -> Some (ValueOf (UniOf term))
forall a (uni :: * -> *). uni (Esc a) -> a -> Some (ValueOf uni)
someValueOf UniOf term (Esc a)
uni
{-# INLINE fromValueOf #-}
fromValue :: forall a term. (HasConstant term, UniOf term `HasTermLevel` a) => a -> term
fromValue :: forall a term.
(HasConstant term, HasTermLevel (UniOf term) a) =>
a -> term
fromValue = UniOf term (Esc a) -> a -> term
forall a term. HasConstant term => UniOf term (Esc a) -> a -> term
fromValueOf UniOf term (Esc a)
forall k (uni :: * -> *) (a :: k). Contains uni a => uni (Esc a)
knownUni
{-# INLINE fromValue #-}
instance HasConstant (Term TyName Name uni fun ()) where
asConstant :: Term TyName Name uni fun ()
-> Either
BuiltinError (Some (ValueOf (UniOf (Term TyName Name uni fun ()))))
asConstant (Constant ()
_ Some (ValueOf uni)
val) = Some (ValueOf uni) -> Either BuiltinError (Some (ValueOf uni))
forall a. a -> Either BuiltinError a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Some (ValueOf uni)
val
asConstant Term TyName Name uni fun ()
_ = Either BuiltinError (Some (ValueOf uni))
Either
BuiltinError (Some (ValueOf (UniOf (Term TyName Name uni fun ()))))
forall (m :: * -> *) void. MonadError BuiltinError m => m void
throwNotAConstant
fromConstant :: Some (ValueOf (UniOf (Term TyName Name uni fun ())))
-> Term TyName Name uni fun ()
fromConstant = () -> Some (ValueOf uni) -> Term TyName Name uni fun ()
forall tyname name (uni :: * -> *) fun ann.
ann -> Some (ValueOf uni) -> Term tyname name uni fun ann
Constant ()