plutus-core-1.0.0.1: Language library for Plutus Core
Safe HaskellNone
LanguageHaskell2010

PlutusCore.DeBruijn

Description

Support for using de Bruijn indices for term and type names.

Synopsis

Documentation

newtype Index Source #

A relative index used for de Bruijn identifiers.

Constructors

Index Word64 

Instances

Instances details
Enum Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Eq Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

(==) :: Index -> Index -> Bool Source #

(/=) :: Index -> Index -> Bool Source #

Integral Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Num Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Ord Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Real Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Generic Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Rep Index :: Type -> Type Source #

Methods

from :: Index -> Rep Index x Source #

to :: Rep Index x -> Index Source #

NFData Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: Index -> () Source #

Pretty Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

pretty :: Index -> Doc ann #

prettyList :: [Index] -> Doc ann #

Flat Index 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: Index -> Encoding

decode :: Get Index

size :: Index -> NumBits -> NumBits

type Rep Index Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep Index = D1 ('MetaData "Index" "PlutusCore.DeBruijn.Internal" "plutus-core-1.0.0.1-6wMiyL0yerXJu56t8zBoKx" 'True) (C1 ('MetaCons "Index" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

newtype DeBruijn Source #

A term name as a de Bruijn index, without the name string.

Constructors

DeBruijn 

Fields

Instances

Instances details
Eq DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Generic DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Rep DeBruijn :: Type -> Type Source #

NFData DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: DeBruijn -> () Source #

HasIndex DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Flat DeBruijn 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: DeBruijn -> Encoding

decode :: Get DeBruijn

size :: DeBruijn -> NumBits -> NumBits

HasPrettyConfigName config => PrettyBy config DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

prettyBy :: config -> DeBruijn -> Doc ann #

prettyListBy :: config -> [DeBruijn] -> Doc ann #

Flat (Binder DeBruijn) 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: Binder DeBruijn -> Encoding

decode :: Get (Binder DeBruijn)

size :: Binder DeBruijn -> NumBits -> NumBits

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term DeBruijn uni fun ann) Source # 
Instance details

Defined in UntypedPlutusCore.Core.Instance.Eq

Methods

(==) :: Term DeBruijn uni fun ann -> Term DeBruijn uni fun ann -> Bool Source #

(/=) :: Term DeBruijn uni fun ann -> Term DeBruijn uni fun ann -> Bool Source #

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term TyDeBruijn DeBruijn uni fun ann) Source # 
Instance details

Defined in PlutusCore.Core.Instance.Eq

Methods

(==) :: Term TyDeBruijn DeBruijn uni fun ann -> Term TyDeBruijn DeBruijn uni fun ann -> Bool Source #

(/=) :: Term TyDeBruijn DeBruijn uni fun ann -> Term TyDeBruijn DeBruijn uni fun ann -> Bool Source #

type Rep DeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep DeBruijn = D1 ('MetaData "DeBruijn" "PlutusCore.DeBruijn.Internal" "plutus-core-1.0.0.1-6wMiyL0yerXJu56t8zBoKx" 'True) (C1 ('MetaCons "DeBruijn" 'PrefixI 'True) (S1 ('MetaSel ('Just "dbnIndex") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Index)))

data NamedDeBruijn Source #

A term name as a de Bruijn index.

Constructors

NamedDeBruijn 

Fields

Instances

Instances details
Eq NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Generic NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Rep NamedDeBruijn :: Type -> Type Source #

NFData NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: NamedDeBruijn -> () Source #

HasIndex NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Flat NamedDeBruijn 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: NamedDeBruijn -> Encoding

decode :: Get NamedDeBruijn

size :: NamedDeBruijn -> NumBits -> NumBits

HasPrettyConfigName config => PrettyBy config NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

prettyBy :: config -> NamedDeBruijn -> Doc ann #

prettyListBy :: config -> [NamedDeBruijn] -> Doc ann #

Flat (Binder NamedDeBruijn) 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: Binder NamedDeBruijn -> Encoding

decode :: Get (Binder NamedDeBruijn)

size :: Binder NamedDeBruijn -> NumBits -> NumBits

PrettyUni uni fun => MonadError (CekEvaluationException NamedDeBruijn uni fun) (CekM uni fun s) 
Instance details

Defined in UntypedPlutusCore.Evaluation.Machine.Cek.Internal

Methods

throwError :: CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a

catchError :: CekM uni fun s a -> (CekEvaluationException NamedDeBruijn uni fun -> CekM uni fun s a) -> CekM uni fun s a

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term NamedDeBruijn uni fun ann) Source # 
Instance details

Defined in UntypedPlutusCore.Core.Instance.Eq

Methods

(==) :: Term NamedDeBruijn uni fun ann -> Term NamedDeBruijn uni fun ann -> Bool Source #

(/=) :: Term NamedDeBruijn uni fun ann -> Term NamedDeBruijn uni fun ann -> Bool Source #

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term NamedTyDeBruijn NamedDeBruijn uni fun ann) Source # 
Instance details

Defined in PlutusCore.Core.Instance.Eq

type Rep NamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep NamedDeBruijn = D1 ('MetaData "NamedDeBruijn" "PlutusCore.DeBruijn.Internal" "plutus-core-1.0.0.1-6wMiyL0yerXJu56t8zBoKx" 'False) (C1 ('MetaCons "NamedDeBruijn" 'PrefixI 'True) (S1 ('MetaSel ('Just "ndbnString") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "ndbnIndex") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Index)))

newtype FakeNamedDeBruijn Source #

A wrapper around nameddebruijn that must hold the invariant of name=fakeName.

Instances

Instances details
Eq FakeNamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show FakeNamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

NFData FakeNamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: FakeNamedDeBruijn -> () Source #

Flat FakeNamedDeBruijn 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: FakeNamedDeBruijn -> Encoding

decode :: Get FakeNamedDeBruijn

size :: FakeNamedDeBruijn -> NumBits -> NumBits

HasPrettyConfigName config => PrettyBy config FakeNamedDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

prettyBy :: config -> FakeNamedDeBruijn -> Doc ann #

prettyListBy :: config -> [FakeNamedDeBruijn] -> Doc ann #

Flat (Binder FakeNamedDeBruijn) 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: Binder FakeNamedDeBruijn -> Encoding

decode :: Get (Binder FakeNamedDeBruijn)

size :: Binder FakeNamedDeBruijn -> NumBits -> NumBits

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term FakeNamedDeBruijn uni fun ann) Source # 
Instance details

Defined in UntypedPlutusCore.Core.Instance.Eq

Methods

(==) :: Term FakeNamedDeBruijn uni fun ann -> Term FakeNamedDeBruijn uni fun ann -> Bool Source #

(/=) :: Term FakeNamedDeBruijn uni fun ann -> Term FakeNamedDeBruijn uni fun ann -> Bool Source #

newtype TyDeBruijn Source #

A type name as a de Bruijn index, without the name string.

Constructors

TyDeBruijn DeBruijn 

Instances

Instances details
Eq TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Generic TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Rep TyDeBruijn :: Type -> Type Source #

NFData TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: TyDeBruijn -> () Source #

Wrapped TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Unwrapped TyDeBruijn

Methods

_Wrapped' :: Iso' TyDeBruijn (Unwrapped TyDeBruijn)

HasIndex TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Flat TyDeBruijn 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: TyDeBruijn -> Encoding

decode :: Get TyDeBruijn

size :: TyDeBruijn -> NumBits -> NumBits

HasPrettyConfigName config => PrettyBy config TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

prettyBy :: config -> TyDeBruijn -> Doc ann #

prettyListBy :: config -> [TyDeBruijn] -> Doc ann #

(GEq uni, Closed uni, Everywhere uni Eq, Eq ann) => Eq (Type TyDeBruijn uni ann) Source # 
Instance details

Defined in PlutusCore.Core.Instance.Eq

Methods

(==) :: Type TyDeBruijn uni ann -> Type TyDeBruijn uni ann -> Bool Source #

(/=) :: Type TyDeBruijn uni ann -> Type TyDeBruijn uni ann -> Bool Source #

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term TyDeBruijn DeBruijn uni fun ann) Source # 
Instance details

Defined in PlutusCore.Core.Instance.Eq

Methods

(==) :: Term TyDeBruijn DeBruijn uni fun ann -> Term TyDeBruijn DeBruijn uni fun ann -> Bool Source #

(/=) :: Term TyDeBruijn DeBruijn uni fun ann -> Term TyDeBruijn DeBruijn uni fun ann -> Bool Source #

type Rep TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep TyDeBruijn = D1 ('MetaData "TyDeBruijn" "PlutusCore.DeBruijn.Internal" "plutus-core-1.0.0.1-6wMiyL0yerXJu56t8zBoKx" 'True) (C1 ('MetaCons "TyDeBruijn" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 DeBruijn)))
type Unwrapped TyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Unwrapped TyDeBruijn = GUnwrapped (Rep TyDeBruijn)

newtype NamedTyDeBruijn Source #

A type name as a de Bruijn index.

Instances

Instances details
Eq NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Generic NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Rep NamedTyDeBruijn :: Type -> Type Source #

NFData NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: NamedTyDeBruijn -> () Source #

Wrapped NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Unwrapped NamedTyDeBruijn

Methods

_Wrapped' :: Iso' NamedTyDeBruijn (Unwrapped NamedTyDeBruijn)

HasIndex NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Flat NamedTyDeBruijn 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: NamedTyDeBruijn -> Encoding

decode :: Get NamedTyDeBruijn

size :: NamedTyDeBruijn -> NumBits -> NumBits

HasPrettyConfigName config => PrettyBy config NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

prettyBy :: config -> NamedTyDeBruijn -> Doc ann #

prettyListBy :: config -> [NamedTyDeBruijn] -> Doc ann #

Flat (Binder NamedTyDeBruijn) 
Instance details

Defined in PlutusCore.Flat

Methods

encode :: Binder NamedTyDeBruijn -> Encoding

decode :: Get (Binder NamedTyDeBruijn)

size :: Binder NamedTyDeBruijn -> NumBits -> NumBits

(GEq uni, Closed uni, Everywhere uni Eq, Eq ann) => Eq (Type NamedTyDeBruijn uni ann) Source # 
Instance details

Defined in PlutusCore.Core.Instance.Eq

Methods

(==) :: Type NamedTyDeBruijn uni ann -> Type NamedTyDeBruijn uni ann -> Bool Source #

(/=) :: Type NamedTyDeBruijn uni ann -> Type NamedTyDeBruijn uni ann -> Bool Source #

(GEq uni, Closed uni, Everywhere uni Eq, Eq fun, Eq ann) => Eq (Term NamedTyDeBruijn NamedDeBruijn uni fun ann) Source # 
Instance details

Defined in PlutusCore.Core.Instance.Eq

type Rep NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep NamedTyDeBruijn = D1 ('MetaData "NamedTyDeBruijn" "PlutusCore.DeBruijn.Internal" "plutus-core-1.0.0.1-6wMiyL0yerXJu56t8zBoKx" 'True) (C1 ('MetaCons "NamedTyDeBruijn" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NamedDeBruijn)))
type Unwrapped NamedTyDeBruijn Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Unwrapped NamedTyDeBruijn = GUnwrapped (Rep NamedTyDeBruijn)

data FreeVariableError Source #

We cannot do a correct translation to or from de Bruijn indices if the program is not well-scoped. So we throw an error in such a case.

Instances

Instances details
Eq FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Ord FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Show FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Generic FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Associated Types

type Rep FreeVariableError :: Type -> Type Source #

Exception FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

NFData FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

Methods

rnf :: FreeVariableError -> () Source #

Pretty FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

HasErrorCode FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

AsFreeVariableError FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

type Rep FreeVariableError = D1 ('MetaData "FreeVariableError" "PlutusCore.DeBruijn.Internal" "plutus-core-1.0.0.1-6wMiyL0yerXJu56t8zBoKx" 'False) (C1 ('MetaCons "FreeUnique" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Unique)) :+: C1 ('MetaCons "FreeIndex" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Index)))

class AsFreeVariableError r where Source #

Minimal complete definition

_FreeVariableError

Instances

Instances details
AsFreeVariableError FreeVariableError Source # 
Instance details

Defined in PlutusCore.DeBruijn.Internal

AsFreeVariableError (Error uni fun ann) Source # 
Instance details

Defined in PlutusCore.Error

Methods

_FreeVariableError :: Prism' (Error uni fun ann) FreeVariableError Source #

_FreeUnique :: Prism' (Error uni fun ann) Unique Source #

_FreeIndex :: Prism' (Error uni fun ann) Index Source #

AsFreeVariableError (Error uni fun a) Source # 
Instance details

Defined in PlutusIR.Error

Methods

_FreeVariableError :: Prism' (Error uni fun a) FreeVariableError Source #

_FreeUnique :: Prism' (Error uni fun a) Unique Source #

_FreeIndex :: Prism' (Error uni fun a) Index Source #

deBruijnTy :: (AsFreeVariableError e, MonadError e m) => Type TyName uni ann -> m (Type NamedTyDeBruijn uni ann) Source #

Convert a Type with TyNames into a Type with NamedTyDeBruijns. Will throw an error if a free variable is encountered.

deBruijnTerm :: (AsFreeVariableError e, MonadError e m) => Term TyName Name uni fun ann -> m (Term NamedTyDeBruijn NamedDeBruijn uni fun ann) Source #

Convert a Term with TyNames and Names into a Term with NamedTyDeBruijns and NamedDeBruijns. Will throw an error if a free variable is encountered.

unDeBruijnTy :: (MonadQuote m, AsFreeVariableError e, MonadError e m) => Type NamedTyDeBruijn uni ann -> m (Type TyName uni ann) Source #

Convert a Type with NamedTyDeBruijns into a Type with TyNames. Will throw an error if a free variable is encountered.

unDeBruijnTerm :: (MonadQuote m, AsFreeVariableError e, MonadError e m) => Term NamedTyDeBruijn NamedDeBruijn uni fun ann -> m (Term TyName Name uni fun ann) Source #

Convert a Term with NamedTyDeBruijns and NamedDeBruijns into a Term with TyNames and Names. Will throw an error if a free variable is encountered.

unsafe api, use with care

deBruijnTyWith :: Monad m => (Unique -> ReaderT Levels m Index) -> Type TyName uni ann -> m (Type NamedTyDeBruijn uni ann) Source #

deBruijnTermWith :: Monad m => (Unique -> ReaderT Levels m Index) -> Term TyName Name uni fun ann -> m (Term NamedTyDeBruijn NamedDeBruijn uni fun ann) Source #

unDeBruijnTyWith :: MonadQuote m => (Index -> ReaderT Levels m Unique) -> Type NamedTyDeBruijn uni ann -> m (Type TyName uni ann) Source #

Takes a "handler" function to execute when encountering free variables.

unDeBruijnTermWith :: MonadQuote m => (Index -> ReaderT Levels m Unique) -> Term NamedTyDeBruijn NamedDeBruijn uni fun ann -> m (Term TyName Name uni fun ann) Source #

Takes a "handler" function to execute when encountering free variables.

freeIndexAsConsistentLevel :: (MonadReader Levels m, MonadState (Map Level Unique) m, MonadQuote m) => Index -> m Unique Source #

A different implementation of a handler, where "free" debruijn indices do not throw an error but are instead gracefully converted to fresh uniques. These generated uniques remain free; i.e. if the original term was open, it will remain open after applying this handler. These generated free uniques are consistent across the open term (by using a state cache).

deBruijnInitIndex :: Index Source #

The LamAbs index (for debruijn indices) and the starting level of DeBruijn monad