Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Conversions between haskell types/values and Michelson ones.
Synopsis
- class WellTypedToT a => IsoValue a where
- isoValue :: (IsoValue a, IsoValue b) => Iso (Value (ToT a)) (Value (ToT b)) a b
- type KnownIsoT a = (IsoValue a, SingI (ToT a))
- class SingI (GValueType x) => GIsoValue (x :: Type -> Type) where
- type GValueType x :: T
- type family ToT' t where ...
- type GenericIsoValue t = (IsoValue t, Generic t, ToT t ~ GValueType (Rep t))
- type WellTypedToT a = (IsoValue a, WellTyped (ToT a))
- type HasNoOpToT a = (IsoValue a, HasNoOp (ToT a))
- data Dict a where
- type EntrypointCall param arg = EntrypointCallT (ToT param) (ToT arg)
- type SomeEntrypointCall arg = SomeEntrypointCallT (ToT arg)
- data ContractRef (arg :: Type) = ContractRef {
- crAddress :: Address
- crEntrypoint :: SomeEntrypointCall arg
- coerceContractRef :: ToT a ~ ToT b => ContractRef a -> ContractRef b
- contractRefToAddr :: ContractRef cp -> EpAddress
- data Ticket (arg :: Type) = Ticket {}
- newtype BigMapId k v = BigMapId {}
- data BigMap k v = BigMap {}
- class ToBigMap m where
- type ToBigMapKey m
- type ToBigMapValue m
- mkBigMap :: m -> BigMap (ToBigMapKey m) (ToBigMapValue m)
- type family ToTs (ts :: [Type]) :: [T] where ...
- type family ToTs' t where ...
- class IsoValuesStack (ts :: [Type]) where
- totsKnownLemma :: forall s. KnownList s :- KnownList (ToTs s)
- totsAppendLemma :: forall a b. KnownList a => Dict (ToTs (a ++ b) ~ (ToTs a ++ ToTs b))
Value conversions
class WellTypedToT a => IsoValue a where Source #
Isomorphism between Michelson values and plain Haskell types.
Default implementation of this typeclass converts ADTs to Michelson "pair"s and "or"s.
Nothing
Type function that converts a regular Haskell type into a T
type.
type ToT a = GValueType (Rep a)
toVal :: a -> Value (ToT a) Source #
Converts a Haskell structure into Value
representation.
default toVal :: (Generic a, GIsoValue (Rep a), ToT a ~ GValueType (Rep a)) => a -> Value (ToT a) Source #
fromVal :: Value (ToT a) -> a Source #
Converts a Value
into Haskell type.
Instances
isoValue :: (IsoValue a, IsoValue b) => Iso (Value (ToT a)) (Value (ToT b)) a b Source #
An optic witnessing the isomorphism between a michelson type and a haskell type.
class SingI (GValueType x) => GIsoValue (x :: Type -> Type) Source #
Implements ADT conversion to Michelson value.
Thanks to Generic, Michelson representation will be a balanced tree; this reduces average access time in general case.
A drawback of such approach is that, in theory, in new GHC version generified representation may change; however, chances are small and I (martoon) believe that contract versions will change much faster anyway.
In case an unbalanced tree is needed, the Generic instance can be derived by using the utilities in the Morley.Util.Generic module.
gToValue, gFromValue
type GValueType x :: T Source #
Instances
type GenericIsoValue t = (IsoValue t, Generic t, ToT t ~ GValueType (Rep t)) Source #
Whether Michelson representation of the type is derived via Generics.
Values of type
capture a dictionary for a constraint of type Dict
pp
.
e.g.
Dict
::Dict
(Eq
Int
)
captures a dictionary that proves we have an:
instanceEq
Int
Pattern matching on the Dict
constructor will bring this instance into scope.
Instances
() :=> (Semigroup (Dict a)) | |
() :=> (Show (Dict a)) | |
() :=> (Eq (Dict a)) | |
() :=> (Ord (Dict a)) | |
a :=> (Monoid (Dict a)) | |
a :=> (Bounded (Dict a)) | |
a :=> (Enum (Dict a)) | |
a :=> (Read (Dict a)) | |
HasDict a (Dict a) | |
Defined in Data.Constraint | |
(Typeable p, p) => Data (Dict p) | |
Defined in Data.Constraint gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Dict p -> c (Dict p) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Dict p) # toConstr :: Dict p -> Constr # dataTypeOf :: Dict p -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Dict p)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Dict p)) # gmapT :: (forall b. Data b => b -> b) -> Dict p -> Dict p # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Dict p -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Dict p -> r # gmapQ :: (forall d. Data d => d -> u) -> Dict p -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Dict p -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Dict p -> m (Dict p) # | |
a => Monoid (Dict a) | |
Semigroup (Dict a) | |
a => Bounded (Dict a) | |
a => Enum (Dict a) | |
Defined in Data.Constraint | |
a => Read (Dict a) | |
Show (Dict a) | |
NFData (Dict c) | |
Defined in Data.Constraint | |
Eq (Dict a) | |
Ord (Dict a) | |
Re-exporting to use in tests.
Missing Haskell analogies to Michelson values
type EntrypointCall param arg = EntrypointCallT (ToT param) (ToT arg) Source #
type SomeEntrypointCall arg = SomeEntrypointCallT (ToT arg) Source #
data ContractRef (arg :: Type) Source #
Since Contract
name is used to designate contract code, lets call
analogy of TContract
type as follows.
Note that type argument always designates an argument of entrypoint.
If a contract has explicit default entrypoint (and no root entrypoint),
ContractRef
referring to it can never have the entire parameter as its
type argument.
Instances
coerceContractRef :: ToT a ~ ToT b => ContractRef a -> ContractRef b Source #
Replace type argument of ContractRef
with isomorphic one.
contractRefToAddr :: ContractRef cp -> EpAddress Source #
data Ticket (arg :: Type) Source #
Ticket type.
Instances
Show arg => Show (Ticket arg) Source # | |
Eq arg => Eq (Ticket arg) Source # | |
PolyTypeHasDocC '[a] => TypeHasDoc (Ticket a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc type TypeDocFieldDescriptions (Ticket a) :: FieldDescriptions Source # typeDocName :: Proxy (Ticket a) -> Text Source # typeDocMdDescription :: Markdown Source # typeDocMdReference :: Proxy (Ticket a) -> WithinParens -> Markdown Source # typeDocDependencies :: Proxy (Ticket a) -> [SomeDocDefinitionItem] Source # typeDocHaskellRep :: TypeDocHaskellRep (Ticket a) Source # typeDocMichelsonRep :: TypeDocMichelsonRep (Ticket a) Source # | |
(Comparable (ToT a), IsoValue a) => IsoValue (Ticket a) Source # | |
type TypeDocFieldDescriptions (Ticket a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
type ToT (Ticket a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value |
Phantom type that represents the ID of a big_map with
keys of type k
and values of type v
.
Instances
(Typeable k2, Typeable v, Typeable k1, Typeable k3) => Data (BigMapId k2 v) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> BigMapId k2 v -> c (BigMapId k2 v) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (BigMapId k2 v) # toConstr :: BigMapId k2 v -> Constr # dataTypeOf :: BigMapId k2 v -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (BigMapId k2 v)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (BigMapId k2 v)) # gmapT :: (forall b. Data b => b -> b) -> BigMapId k2 v -> BigMapId k2 v # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> BigMapId k2 v -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> BigMapId k2 v -> r # gmapQ :: (forall d. Data d => d -> u) -> BigMapId k2 v -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> BigMapId k2 v -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> BigMapId k2 v -> m (BigMapId k2 v) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> BigMapId k2 v -> m (BigMapId k2 v) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> BigMapId k2 v -> m (BigMapId k2 v) # | |
Num (BigMapId k2 v) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value (+) :: BigMapId k2 v -> BigMapId k2 v -> BigMapId k2 v # (-) :: BigMapId k2 v -> BigMapId k2 v -> BigMapId k2 v # (*) :: BigMapId k2 v -> BigMapId k2 v -> BigMapId k2 v # negate :: BigMapId k2 v -> BigMapId k2 v # abs :: BigMapId k2 v -> BigMapId k2 v # signum :: BigMapId k2 v -> BigMapId k2 v # fromInteger :: Integer -> BigMapId k2 v # | |
Show (BigMapId k2 v) Source # | |
Buildable (BigMapId k2 v) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value | |
IsoValue (BigMapId k2 v) Source # | |
type ToT (BigMapId k2 v) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value |
Instances
class ToBigMap m where Source #
type ToBigMapKey m Source #
type ToBigMapValue m Source #
mkBigMap :: m -> BigMap (ToBigMapKey m) (ToBigMapValue m) Source #
Instances
Stack conversion
type family ToTs (ts :: [Type]) :: [T] where ... Source #
Type function to convert a Haskell stack type to T
-based one.
class IsoValuesStack (ts :: [Type]) where Source #
Isomorphism between Michelson stack and its Haskell reflection.
toValStack :: Rec Identity ts -> Rec Value (ToTs ts) Source #
fromValStack :: Rec Value (ToTs ts) -> Rec Identity ts Source #
Instances
IsoValuesStack ('[] :: [Type]) Source # | |
(IsoValue t, IsoValuesStack st) => IsoValuesStack (t ': st) Source # | |