Safe Haskell | None |
---|---|
Language | Haskell2010 |
Primitives supplying entrypoints declarations and lookup.
Synopsis
- type family CanHaveEntrypoints (p :: Type) :: Bool where ...
- class EntrypointsDerivation deriv cp where
- type EpdAllEntrypoints deriv cp :: [(Symbol, Type)]
- type EpdLookupEntrypoint deriv cp :: Symbol -> Exp (Maybe Type)
- epdNotes :: (Notes (ToT cp), RootAnn)
- epdCall :: ParameterScope (ToT cp) => Label name -> EpConstructionRes (ToT cp) (Eval (EpdLookupEntrypoint deriv cp name))
- epdDescs :: Rec EpCallingDesc (EpdAllEntrypoints deriv cp)
- data EpConstructionRes (param :: T) (marg :: Maybe Type) where
- EpConstructed :: ParameterScope (ToT arg) => EpLiftSequence (ToT arg) param -> EpConstructionRes param ('Just arg)
- EpConstructionFailed :: EpConstructionRes param 'Nothing
- data EpCallingDesc (info :: (Symbol, Type)) where
- EpCallingDesc :: {..} -> EpCallingDesc '(name, arg)
- data EpCallingStep = EpsWrapIn Text
- type RequireAllUniqueEntrypoints cp = RequireAllUniqueEntrypoints' (ParameterEntrypointsDerivation cp) cp
- class (EntrypointsDerivation (ParameterEntrypointsDerivation cp) cp, RequireAllUniqueEntrypoints cp) => ParameterHasEntrypoints cp where
- type ParameterEntrypointsDerivation cp :: Type
- type ParameterDeclaresEntrypoints cp = (If (CanHaveEntrypoints cp) (ParameterHasEntrypoints cp) (() :: Constraint), NiceParameter cp, EntrypointsDerivation (GetParameterEpDerivation cp) cp)
- type GetParameterEpDerivation cp = If (CanHaveEntrypoints cp) (ParameterEntrypointsDerivation cp) EpdNone
- pepNotes :: forall cp. ParameterDeclaresEntrypoints cp => (Notes (ToT cp), RootAnn)
- pepCall :: forall cp name. (ParameterDeclaresEntrypoints cp, ParameterScope (ToT cp)) => Label name -> EpConstructionRes (ToT cp) (Eval (LookupParameterEntrypoint cp name))
- pepDescs :: forall cp. ParameterDeclaresEntrypoints cp => Rec EpCallingDesc (AllParameterEntrypoints cp)
- pepDescsWithDef :: forall cp. ParameterDeclaresEntrypoints cp => [Some1 EpCallingDesc]
- type family AllParameterEntrypoints (cp :: Type) :: [(Symbol, Type)] where ...
- type family LookupParameterEntrypoint (cp :: Type) :: Symbol -> Exp (Maybe Type) where ...
- parameterEntrypointsToNotes :: forall cp. ParameterDeclaresEntrypoints cp => ParamNotes (ToT cp)
- type GetEntrypointArg cp name = Eval (LiftM2 FromMaybe (TError (('Text "Entrypoint not found: " :<>: 'ShowType name) :$$: (('Text "In contract parameter `" :<>: 'ShowType cp) :<>: 'Text "`"))) (LookupParameterEntrypoint cp name))
- parameterEntrypointCall :: forall cp name. ParameterDeclaresEntrypoints cp => Label name -> EntrypointCall cp (GetEntrypointArg cp name)
- type GetDefaultEntrypointArg cp = Eval (LiftM2 FromMaybe (Pure cp) (LookupParameterEntrypoint cp DefaultEpName))
- parameterEntrypointCallDefault :: forall cp. ParameterDeclaresEntrypoints cp => EntrypointCall cp (GetDefaultEntrypointArg cp)
- type ForbidExplicitDefaultEntrypoint cp = Eval (LiftM3 UnMaybe (Pure (Pure (() :: Constraint))) (TError ('Text "Parameter used here must have no explicit \"default\" entrypoint" :$$: (('Text "In parameter type `" :<>: 'ShowType cp) :<>: 'Text "`"))) (LookupParameterEntrypoint cp DefaultEpName))
- type NoExplicitDefaultEntrypoint cp = Eval (LookupParameterEntrypoint cp DefaultEpName) ~ 'Nothing
- sepcCallRootChecked :: forall cp. (NiceParameter cp, ForbidExplicitDefaultEntrypoint cp) => SomeEntrypointCall cp
- data EntrypointRef (mname :: Maybe Symbol) where
- CallDefault :: EntrypointRef 'Nothing
- Call :: NiceEntrypointName name => EntrypointRef ('Just name)
- type NiceEntrypointName name = (KnownSymbol name, ForbidDefaultName name)
- eprName :: forall mname. EntrypointRef mname -> EpName
- type family GetEntrypointArgCustom cp mname :: Type where ...
- newtype TrustEpName = TrustEpName EpName
- class HasEntrypointArg cp name arg where
- useHasEntrypointArg :: name -> (Dict (ParameterScope (ToT arg)), EpName)
- type HasDefEntrypointArg cp defEpName defArg = (defEpName ~ EntrypointRef 'Nothing, HasEntrypointArg cp defEpName defArg)
- type HasEntrypointOfType param con exp = (GetEntrypointArgCustom param ('Just con) ~ exp, ParameterDeclaresEntrypoints param)
- type family ParameterContainsEntrypoints param (fields :: [NamedEp]) :: Constraint where ...
- parameterEntrypointCallCustom :: forall cp mname. ParameterDeclaresEntrypoints cp => EntrypointRef mname -> EntrypointCall cp (GetEntrypointArgCustom cp mname)
- data EpdNone
- type (:>) n ty = 'NamedEp n ty
- type RequireAllUniqueEntrypoints' deriv cp = RequireAllUnique "entrypoint name" (Eval (Map Fst $ EpdAllEntrypoints deriv cp))
Documentation
type family CanHaveEntrypoints (p :: Type) :: Bool where ... Source #
Used to understand whether a type can potentially declare any entrypoints.
CanHaveEntrypoints (ShouldHaveEntrypoints _) = 'True | |
CanHaveEntrypoints p = CanHaveEntrypointsT (ToT p) |
class EntrypointsDerivation deriv cp where Source #
Defines a generalized way to declare entrypoints for various parameter types.
When defining instances of this typeclass, set concrete deriv
argument
and leave variable cp
argument.
Also keep in mind, that in presence of explicit default entrypoint, all other
Or
arms should be callable, though you can put this burden on user if very
necessary.
Methods of this typeclass aim to better type-safety when making up an implementation and they may be not too convenient to use; users should exploit their counterparts.
type EpdAllEntrypoints deriv cp :: [(Symbol, Type)] Source #
Name and argument of each entrypoint. This may include intermediate ones, even root if necessary.
Touching this type family is costly (O(N^2)
), don't use it often.
Note [order of entrypoints children]:
If this contains entrypoints referring to indermediate nodes (not leaves)
in or
tree, then each such entrypoint should be mentioned eariler than
all of its children.
type EpdLookupEntrypoint deriv cp :: Symbol -> Exp (Maybe Type) Source #
Get entrypoint argument by name.
epdNotes :: (Notes (ToT cp), RootAnn) Source #
Construct parameter annotations corresponding to expected entrypoints set.
This method is implementation detail, for actual notes construction
use parameterEntrypointsToNotes
.
epdCall :: ParameterScope (ToT cp) => Label name -> EpConstructionRes (ToT cp) (Eval (EpdLookupEntrypoint deriv cp name)) Source #
Construct entrypoint caller.
This does not treat calls to default entrypoint in a special way.
This method is implementation detail, for actual entrypoint lookup
use parameterEntrypointCall
.
epdDescs :: Rec EpCallingDesc (EpdAllEntrypoints deriv cp) Source #
Description of how each of the entrypoints is constructed.
Instances
data EpConstructionRes (param :: T) (marg :: Maybe Type) where Source #
Result of entrypoint lookup at term level.
EpConstructed :: ParameterScope (ToT arg) => EpLiftSequence (ToT arg) param -> EpConstructionRes param ('Just arg) | |
EpConstructionFailed :: EpConstructionRes param 'Nothing |
data EpCallingDesc (info :: (Symbol, Type)) where Source #
How one of the entrypoints is called.
Type arguments are name of the constructor which eventually gave name to the entrypoint and this entrypoint's argument.
EpCallingDesc | |
|
Instances
Show (EpCallingDesc info) Source # | |
Defined in Lorentz.Entrypoints.Core showsPrec :: Int -> EpCallingDesc info -> ShowS # show :: EpCallingDesc info -> String # showList :: [EpCallingDesc info] -> ShowS # |
data EpCallingStep Source #
Instances
Eq EpCallingStep Source # | |
Defined in Lorentz.Entrypoints.Core (==) :: EpCallingStep -> EpCallingStep -> Bool # (/=) :: EpCallingStep -> EpCallingStep -> Bool # | |
Show EpCallingStep Source # | |
Defined in Lorentz.Entrypoints.Core showsPrec :: Int -> EpCallingStep -> ShowS # show :: EpCallingStep -> String # showList :: [EpCallingStep] -> ShowS # |
type RequireAllUniqueEntrypoints cp = RequireAllUniqueEntrypoints' (ParameterEntrypointsDerivation cp) cp Source #
Ensure that all declared entrypoints are unique.
class (EntrypointsDerivation (ParameterEntrypointsDerivation cp) cp, RequireAllUniqueEntrypoints cp) => ParameterHasEntrypoints cp Source #
Which entrypoints given parameter declares.
Note that usually this function should not be used as constraint, use
ParameterDeclaresEntrypoints
for this purpose.
type ParameterEntrypointsDerivation cp :: Type Source #
Instances
(NiceParameter cp, EntrypointsDerivation epd cp, RequireAllUniqueEntrypoints' epd cp) => ParameterHasEntrypoints (ParameterWrapper epd cp) Source # | |
Defined in Lorentz.Entrypoints.Manual type ParameterEntrypointsDerivation (ParameterWrapper epd cp) Source # |
type ParameterDeclaresEntrypoints cp = (If (CanHaveEntrypoints cp) (ParameterHasEntrypoints cp) (() :: Constraint), NiceParameter cp, EntrypointsDerivation (GetParameterEpDerivation cp) cp) Source #
Parameter declares some entrypoints.
This is a version of ParameterHasEntrypoints
which we actually use in
constraints. When given type is a sum type or newtype, we refer to
ParameterHasEntrypoints
instance, otherwise this instance is not
necessary.
type GetParameterEpDerivation cp = If (CanHaveEntrypoints cp) (ParameterEntrypointsDerivation cp) EpdNone Source #
Version of ParameterEntrypointsDerivation
which we actually use in
function signatures. When given type is sum type or newtype, we refer to
ParameterEntrypointsDerivation
, otherwise we suppose that no entrypoints
are declared.
pepNotes :: forall cp. ParameterDeclaresEntrypoints cp => (Notes (ToT cp), RootAnn) Source #
Version of epdNotes
which we actually use in code.
It hides derivations stuff inside, and treats primitive types specially
like GetParameterEpDerivation
does.
pepCall :: forall cp name. (ParameterDeclaresEntrypoints cp, ParameterScope (ToT cp)) => Label name -> EpConstructionRes (ToT cp) (Eval (LookupParameterEntrypoint cp name)) Source #
Version of epdCall
which we actually use in code.
It hides derivations stuff inside, and treats primitive types specially
like GetParameterEpDerivation
does.
pepDescs :: forall cp. ParameterDeclaresEntrypoints cp => Rec EpCallingDesc (AllParameterEntrypoints cp) Source #
Version of epdDescs
which we actually use in code.
It hides derivations stuff inside, and treats primitive types specially
like GetParameterEpDerivation
does.
pepDescsWithDef :: forall cp. ParameterDeclaresEntrypoints cp => [Some1 EpCallingDesc] Source #
Descriptions of how each of the entrypoints is constructed.
Similar to pepDescs
, but includes default entrypoint disregard whether it is
explicit or not, while pepDescs
includes it only if it is explicit.
Also this returns list, not Rec
, for simplicity.
Note that [order of entrypoints children] property still holds here.
type family AllParameterEntrypoints (cp :: Type) :: [(Symbol, Type)] where ... Source #
Get all entrypoints declared for parameter.
type family LookupParameterEntrypoint (cp :: Type) :: Symbol -> Exp (Maybe Type) where ... Source #
Lookup for entrypoint type by name.
Does not treat default entrypoints in a special way.
parameterEntrypointsToNotes :: forall cp. ParameterDeclaresEntrypoints cp => ParamNotes (ToT cp) Source #
Derive annotations for given parameter.
type GetEntrypointArg cp name = Eval (LiftM2 FromMaybe (TError (('Text "Entrypoint not found: " :<>: 'ShowType name) :$$: (('Text "In contract parameter `" :<>: 'ShowType cp) :<>: 'Text "`"))) (LookupParameterEntrypoint cp name)) Source #
Get type of entrypoint with given name, fail if not found.
parameterEntrypointCall :: forall cp name. ParameterDeclaresEntrypoints cp => Label name -> EntrypointCall cp (GetEntrypointArg cp name) Source #
Prepare call to given entrypoint.
This does not treat calls to default entrypoint in a special way.
To call default entrypoint properly use parameterEntrypointCallDefault
.
type GetDefaultEntrypointArg cp = Eval (LiftM2 FromMaybe (Pure cp) (LookupParameterEntrypoint cp DefaultEpName)) Source #
Get type of entrypoint with given name, fail if not found.
parameterEntrypointCallDefault :: forall cp. ParameterDeclaresEntrypoints cp => EntrypointCall cp (GetDefaultEntrypointArg cp) Source #
Call the default entrypoint.
type ForbidExplicitDefaultEntrypoint cp = Eval (LiftM3 UnMaybe (Pure (Pure (() :: Constraint))) (TError ('Text "Parameter used here must have no explicit \"default\" entrypoint" :$$: (('Text "In parameter type `" :<>: 'ShowType cp) :<>: 'Text "`"))) (LookupParameterEntrypoint cp DefaultEpName)) Source #
Ensure that there is no explicit "default" entrypoint.
type NoExplicitDefaultEntrypoint cp = Eval (LookupParameterEntrypoint cp DefaultEpName) ~ 'Nothing Source #
Similar to ForbidExplicitDefaultEntrypoint
, but in a version which
the compiler can work with (and which produces errors confusing for users :/)
sepcCallRootChecked :: forall cp. (NiceParameter cp, ForbidExplicitDefaultEntrypoint cp) => SomeEntrypointCall cp Source #
Call root entrypoint safely.
data EntrypointRef (mname :: Maybe Symbol) where Source #
Which entrypoint to call.
We intentionally distinguish default and non-default cases because this makes API more details-agnostic.
CallDefault :: EntrypointRef 'Nothing | Call the default entrypoint, or root if no explicit default is assigned. |
Call :: NiceEntrypointName name => EntrypointRef ('Just name) | Call the given entrypoint; calling default is not treated specially. You have to provide entrypoint name via passing it as type argument. Unfortunatelly, here we cannot accept a label because in most cases our entrypoints begin from capital letter (being derived from constructor name), while labels must start from a lower-case letter, and there is no way to make a conversion at type-level. |
Instances
(GetEntrypointArgCustom cp mname ~ arg, ParameterDeclaresEntrypoints cp) => HasEntrypointArg (cp :: Type) (EntrypointRef mname) arg Source # | |
Defined in Lorentz.Entrypoints.Core useHasEntrypointArg :: EntrypointRef mname -> (Dict (ParameterScope (ToT arg)), EpName) Source # |
type NiceEntrypointName name = (KnownSymbol name, ForbidDefaultName name) Source #
Constraint on type-level entrypoint name specifier.
eprName :: forall mname. EntrypointRef mname -> EpName Source #
type family GetEntrypointArgCustom cp mname :: Type where ... Source #
Universal entrypoint lookup.
GetEntrypointArgCustom cp 'Nothing = GetDefaultEntrypointArg cp | |
GetEntrypointArgCustom cp ('Just name) = GetEntrypointArg cp name |
newtype TrustEpName Source #
This wrapper allows to pass untyped EpName
and bypass checking
that entrypoint with given name and type exists.
Instances
NiceParameter arg => HasEntrypointArg (cp :: k) TrustEpName arg Source # | |
Defined in Lorentz.Entrypoints.Core useHasEntrypointArg :: TrustEpName -> (Dict (ParameterScope (ToT arg)), EpName) Source # |
class HasEntrypointArg cp name arg where Source #
When we call a Lorentz contract we should pass entrypoint name
and corresponding argument. Ideally we want to statically check
that parameter has entrypoint with given name and
argument. Constraint defined by this type class holds for contract
with parameter cp
that have entrypoint matching name
with type
arg
.
In order to check this property statically, we need to know entrypoint
name in compile time, EntrypointRef
type serves this purpose.
If entrypoint name is not known, one can use TrustEpName
wrapper
to take responsibility for presence of this entrypoint.
If you want to call a function which has this constraint, you have
two options:
1. Pass contract parameter cp
using type application, pass EntrypointRef
as a value and pass entrypoint argument. Type system will check that
cp
has an entrypoint with given reference and type.
2. Pass EpName
wrapped into TrustEpName
and entrypoint argument.
In this case passing contract parameter is not necessary, you do not even
have to know it.
useHasEntrypointArg :: name -> (Dict (ParameterScope (ToT arg)), EpName) Source #
Data returned by this method may look somewhat arbitrary.
EpName
is obviously needed because name
can be
EntrypointRef
or TrustEpName
. Dict
is returned because in
EntrypointRef
case we get this evidence for free and don't want
to use it. We seem to always need it anyway.
Instances
NiceParameter arg => HasEntrypointArg (cp :: k) TrustEpName arg Source # | |
Defined in Lorentz.Entrypoints.Core useHasEntrypointArg :: TrustEpName -> (Dict (ParameterScope (ToT arg)), EpName) Source # | |
(GetEntrypointArgCustom cp mname ~ arg, ParameterDeclaresEntrypoints cp) => HasEntrypointArg (cp :: Type) (EntrypointRef mname) arg Source # | |
Defined in Lorentz.Entrypoints.Core useHasEntrypointArg :: EntrypointRef mname -> (Dict (ParameterScope (ToT arg)), EpName) Source # |
type HasDefEntrypointArg cp defEpName defArg = (defEpName ~ EntrypointRef 'Nothing, HasEntrypointArg cp defEpName defArg) Source #
HasEntrypointArg
constraint specialized to default entrypoint.
type HasEntrypointOfType param con exp = (GetEntrypointArgCustom param ('Just con) ~ exp, ParameterDeclaresEntrypoints param) Source #
Checks that the given parameter consists of some specific entrypoint. Similar as
HasEntrypointArg
but ensures that the argument matches the following datatype.
type family ParameterContainsEntrypoints param (fields :: [NamedEp]) :: Constraint where ... Source #
Check that the given entrypoint has some fields inside. This interface allows for an abstraction of contract parameter so that it requires some *minimal* specification, but not a concrete one.
ParameterContainsEntrypoints _ '[] = () | |
ParameterContainsEntrypoints param ((n :> ty) ': rest) = (HasEntrypointOfType param n ty, ParameterContainsEntrypoints param rest) |
parameterEntrypointCallCustom :: forall cp mname. ParameterDeclaresEntrypoints cp => EntrypointRef mname -> EntrypointCall cp (GetEntrypointArgCustom cp mname) Source #
Universal entrypoint calling.
No entrypoints declared, parameter type will serve as argument type of the only existing entrypoint (default one).
Instances
HasAnnotation cp => EntrypointsDerivation EpdNone cp Source # | |
Defined in Lorentz.Entrypoints.Core | |
type EpdAllEntrypoints EpdNone cp Source # | |
Defined in Lorentz.Entrypoints.Core | |
type EpdLookupEntrypoint EpdNone cp Source # | |
Internals
type RequireAllUniqueEntrypoints' deriv cp = RequireAllUnique "entrypoint name" (Eval (Map Fst $ EpdAllEntrypoints deriv cp)) Source #