-- SPDX-FileCopyrightText: 2020 Tocqueville Group -- -- SPDX-License-Identifier: LicenseRef-MIT-TQ {-# LANGUAGE UndecidableSuperClasses #-} -- | Scope-related constraints used in Lorentz. -- -- This contains constraints from 'Michelson.Typed.Scope' modified for use -- in Lorentz. module Lorentz.Constraints.Scopes ( -- * Grouped constraints NiceComparable , NiceConstant , Dupable , NiceFullPackedValue , NicePackedValue , NiceParameter , NicePrintedValue , NiceStorage , NiceUnpackedValue , NiceNoBigMap , niceParameterEvi , niceStorageEvi , niceConstantEvi , dupableEvi , nicePackedValueEvi , niceUnpackedValueEvi , nicePrintedValueEvi -- * Individual constraints (internals) , CanHaveBigMap , KnownValue , NoOperation , NoContractType , NoBigMap , -- * Re-exports withDict ) where import Data.Constraint (evidence, trans, weaken1) import Lorentz.Annotation (HasAnnotation) import Michelson.Typed -- We write these constraints as class + instance, rather than -- type aliases, in order to allow their partial application. -- | Gathers constraints, commonly required for values. class (IsoValue a, Typeable a) => KnownValue a instance (IsoValue a, Typeable a) => KnownValue a -- | Ensure given type does not contain "operation". class (ForbidOp (ToT a), IsoValue a) => NoOperation a instance (ForbidOp (ToT a), IsoValue a) => NoOperation a class (ForbidContract (ToT a), IsoValue a) => NoContractType a instance (ForbidContract (ToT a), IsoValue a) => NoContractType a class (ForbidBigMap (ToT a), IsoValue a) => NoBigMap a instance (ForbidBigMap (ToT a), IsoValue a) => NoBigMap a class (HasNoNestedBigMaps (ToT a), IsoValue a) => CanHaveBigMap a instance (HasNoNestedBigMaps (ToT a), IsoValue a) => CanHaveBigMap a -- | Constraint applied to any part of parameter type. -- -- Note that you don't usually apply this constraint to the whole parameter, -- consider using 'Lorentz.Constraints.Derivative.NiceParameterFull' in such case. -- -- Using this type is justified e.g. when calling another contract, there -- you usually supply an entrypoint argument, not the whole parameter. type NiceParameter a = (ProperParameterBetterErrors (ToT a), KnownValue a) type NiceStorage a = (ProperStorageBetterErrors (ToT a), HasAnnotation a, KnownValue a) type NiceConstant a = (ProperConstantBetterErrors (ToT a), KnownValue a) type Dupable a = (ProperDupableBetterErrors (ToT a), KnownValue a) type NicePackedValue a = (ProperPackedValBetterErrors (ToT a), KnownValue a) type NiceUnpackedValue a = (ProperUnpackedValBetterErrors (ToT a), KnownValue a) type NiceFullPackedValue a = (NicePackedValue a, NiceUnpackedValue a) type NicePrintedValue a = (ProperPrintedValBetterErrors (ToT a), KnownValue a) type NiceComparable n = (Comparable (ToT n), KnownValue n) type NiceNoBigMap n = (KnownValue n, HasNoBigMap (ToT n)) niceParameterEvi :: forall a. NiceParameter a :- ParameterScope (ToT a) niceParameterEvi = properParameterEvi @(ToT a) `trans` weaken1 niceStorageEvi :: forall a. NiceStorage a :- StorageScope (ToT a) niceStorageEvi = Sub (evidence $ properStorageEvi @(ToT a)) niceConstantEvi :: forall a. NiceConstant a :- ConstantScope (ToT a) niceConstantEvi = properConstantEvi @(ToT a) `trans` weaken1 dupableEvi :: forall a. Dupable a :- DupableScope (ToT a) dupableEvi = properDupableEvi @(ToT a) `trans` weaken1 nicePackedValueEvi :: forall a. NicePackedValue a :- PackedValScope (ToT a) nicePackedValueEvi = properPackedValEvi @(ToT a) `trans` weaken1 niceUnpackedValueEvi :: forall a. NiceUnpackedValue a :- UnpackedValScope (ToT a) niceUnpackedValueEvi = properUnpackedValEvi @(ToT a) `trans` weaken1 nicePrintedValueEvi :: forall a. NicePrintedValue a :- PrintedValScope (ToT a) nicePrintedValueEvi = properPrintedValEvi @(ToT a) `trans` weaken1