Safe Haskell | None |
---|---|
Language | Haskell2010 |
Haskell-Michelson conversions.
Synopsis
- newtype BigMap k v = BigMap {}
- newtype ContractAddr (cp :: Type) = ContractAddr {}
- type IsComparable c = ToT c ~ Tc (ToCT c)
- type family ToTs' (t :: [k]) :: [T] where ...
- type family ToT' (t :: k) :: T where ...
- type family ToTs (ts :: [Type]) :: [T] where ...
- class IsoValue a where
- class IsoCValue a where
- type InstrConstructC dt = (IsoValue dt, Generic dt, GInstrConstruct (Rep dt), GValueType (Rep dt) ~ ToT dt)
- type ConstructorFieldTypes dt = GFieldTypes (Rep dt)
- newtype FieldConstructor (st :: [k]) (field :: Type) = FieldConstructor (Instr (ToTs' st) (ToT field ': ToTs' st))
- type InstrSetFieldC dt name = (IsoValue dt, Generic dt, GInstrSetField name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)), GValueType (Rep dt) ~ ToT dt)
- type InstrGetFieldC dt name = (IsoValue dt, Generic dt, GInstrGet name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)), GValueType (Rep dt) ~ ToT dt)
- type GetFieldType dt name = LnrFieldType (GetNamed name dt)
- instrGetField :: forall dt name st. InstrGetFieldC dt name => Label name -> Instr (ToT dt ': st) (ToT (GetFieldType dt name) ': st)
- instrSetField :: forall dt name st. InstrSetFieldC dt name => Label name -> Instr (ToT (GetFieldType dt name) ': (ToT dt ': st)) (ToT dt ': st)
- instrConstruct :: forall dt st. InstrConstructC dt => Rec (FieldConstructor st) (ConstructorFieldTypes dt) -> Instr st (ToT dt ': st)
- type InstrUnwrapC dt name = (IsoValue dt, Generic dt, GInstrUnwrap (Rep dt) (LnrBranch (GetNamed name dt)) (CtorOnlyField name dt), GValueType (Rep dt) ~ ToT dt)
- type CaseClauses a = GCaseClauses (Rep a)
- data CaseClause (inp :: [T]) (out :: [T]) (param :: CaseClauseParam) where
- CaseClause :: Instr (AppendCtorField x inp) out -> CaseClause inp out (CaseClauseParam ctor x)
- data CaseClauseParam = CaseClauseParam Symbol CtorField
- type InstrCaseC dt inp out = (IsoValue dt, GInstrCase (Rep dt), GValueType (Rep dt) ~ ToT dt)
- data MyCompoundType
- type InstrWrapC dt name = (IsoValue dt, Generic dt, GInstrWrap (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)), GValueType (Rep dt) ~ ToT dt)
- type CtorOnlyField name dt = RequireOneField name (GetCtorField dt name)
- type CtorHasOnlyField ctor dt f = GetCtorField dt ctor ~ OneField f
- type GetCtorField dt ctor = LnrFieldType (GetNamed ctor dt)
- type AppendCtorFieldAxiom (cf :: CtorField) (st :: [Type]) = ToTs (AppendCtorField cf st) ~ AppendCtorField cf (ToTs st)
- type family AppendCtorField (cf :: CtorField) (l :: [k]) :: [k] where ...
- type family ExtractCtorField (cf :: CtorField) where ...
- data CtorField
- appendCtorFieldAxiom :: (AppendCtorFieldAxiom (OneField Word) '[Int], AppendCtorFieldAxiom NoFields '[Int]) => Dict (AppendCtorFieldAxiom cf st)
- instrWrap :: forall dt name st. InstrWrapC dt name => Label name -> Instr (AppendCtorField (GetCtorField dt name) st) (ToT dt ': st)
- hsWrap :: forall dt name. InstrWrapC dt name => Label name -> ExtractCtorField (GetCtorField dt name) -> dt
- instrCase :: forall dt out inp. InstrCaseC dt inp out => Rec (CaseClause inp out) (CaseClauses dt) -> Instr (ToT dt ': inp) out
- (//->) :: Label ("c" `AppendSymbol` ctor) -> Instr (AppendCtorField x inp) out -> CaseClause inp out (CaseClauseParam ctor x)
- instrUnwrapUnsafe :: forall dt name st. InstrUnwrapC dt name => Label name -> Instr (ToT dt ': st) (ToT (CtorOnlyField name dt) ': st)
- hsUnwrap :: forall dt name. InstrUnwrapC dt name => Label name -> dt -> Maybe (CtorOnlyField name dt)
Documentation
Instances
newtype ContractAddr (cp :: Type) Source #
Since Contract
name is used to designate contract code, lets call
analogy of TContract
type as follows.
Instances
IsoValue (ContractAddr cp) Source # | |
Defined in Michelson.Typed.Haskell.Value type ToT (ContractAddr cp) :: T Source # toVal :: ContractAddr cp -> Value (ToT (ContractAddr cp)) Source # fromVal :: Value (ToT (ContractAddr cp)) -> ContractAddr cp Source # | |
type ToT (ContractAddr cp) Source # | |
Defined in Michelson.Typed.Haskell.Value |
type family ToTs' (t :: [k]) :: [T] where ... Source #
Overloaded version of ToTs
to work on Haskell and T
stacks.
type family ToT' (t :: k) :: T where ... Source #
Overloaded version of ToT
to work on Haskell and T
types.
type family ToTs (ts :: [Type]) :: [T] where ... Source #
Type function to convert a Haskell stack type to T
-based one.
class 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
toVal :: a -> Value (ToT a) Source #
Converts a Haskell structure into Value
representation.
toVal :: (Generic a, GIsoValue (Rep a), ToT a ~ GValueType (Rep a)) => a -> Value (ToT a) Source #
Converts a Haskell structure into Value
representation.
fromVal :: Value (ToT a) -> a Source #
Converts a Value
into Haskell type.
fromVal :: (Generic a, GIsoValue (Rep a), ToT a ~ GValueType (Rep a)) => Value (ToT a) -> a Source #
Converts a Value
into Haskell type.
Instances
class IsoCValue a where Source #
Isomorphism between Michelson primitive values and plain Haskell types.
Type function that converts a regular Haskell type into a comparable type
(which has kind CT
).
toCVal :: a -> CValue (ToCT a) Source #
Converts a single Haskell value into CVal
representation.
fromCVal :: CValue (ToCT a) -> a Source #
Converts a CVal
value into a single Haskell value.
Instances
IsoCValue Bool Source # | |
IsoCValue Integer Source # | |
IsoCValue Natural Source # | |
IsoCValue ByteString Source # | |
Defined in Michelson.Typed.Haskell.Value type ToCT ByteString :: CT Source # toCVal :: ByteString -> CValue (ToCT ByteString) Source # fromCVal :: CValue (ToCT ByteString) -> ByteString Source # | |
(DoNotUseTextError :: Constraint) => IsoCValue Text Source # | |
IsoCValue MText Source # | |
IsoCValue Timestamp Source # | |
IsoCValue Mutez Source # | |
IsoCValue KeyHash Source # | |
IsoCValue Address Source # | |
type InstrConstructC dt = (IsoValue dt, Generic dt, GInstrConstruct (Rep dt), GValueType (Rep dt) ~ ToT dt) Source #
Constraint for instrConstruct
.
type ConstructorFieldTypes dt = GFieldTypes (Rep dt) Source #
Types of all fields in a datatype.
newtype FieldConstructor (st :: [k]) (field :: Type) Source #
Way to construct one of the fields in a complex datatype.
FieldConstructor (Instr (ToTs' st) (ToT field ': ToTs' st)) |
type InstrSetFieldC dt name = (IsoValue dt, Generic dt, GInstrSetField name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)), GValueType (Rep dt) ~ ToT dt) Source #
Constraint for instrSetField
.
type InstrGetFieldC dt name = (IsoValue dt, Generic dt, GInstrGet name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)), GValueType (Rep dt) ~ ToT dt) Source #
Constraint for instrGetField
.
type GetFieldType dt name = LnrFieldType (GetNamed name dt) Source #
Get type of field by datatype it is contained in and field name.
instrGetField :: forall dt name st. InstrGetFieldC dt name => Label name -> Instr (ToT dt ': st) (ToT (GetFieldType dt name) ': st) Source #
Make an instruction which accesses given field of the given datatype.
instrSetField :: forall dt name st. InstrSetFieldC dt name => Label name -> Instr (ToT (GetFieldType dt name) ': (ToT dt ': st)) (ToT dt ': st) Source #
For given complex type dt
and its field fieldTy
update the field value.
instrConstruct :: forall dt st. InstrConstructC dt => Rec (FieldConstructor st) (ConstructorFieldTypes dt) -> Instr st (ToT dt ': st) Source #
For given complex type dt
and its field fieldTy
update the field value.
type InstrUnwrapC dt name = (IsoValue dt, Generic dt, GInstrUnwrap (Rep dt) (LnrBranch (GetNamed name dt)) (CtorOnlyField name dt), GValueType (Rep dt) ~ ToT dt) Source #
type CaseClauses a = GCaseClauses (Rep a) Source #
List of CaseClauseParam
s required to pattern match on the given type.
data CaseClause (inp :: [T]) (out :: [T]) (param :: CaseClauseParam) where Source #
Type information about single case clause.
CaseClause :: Instr (AppendCtorField x inp) out -> CaseClause inp out (CaseClauseParam ctor x) |
data CaseClauseParam Source #
In what different case branches differ - related constructor name and input stack type which the branch starts with.
type InstrCaseC dt inp out = (IsoValue dt, GInstrCase (Rep dt), GValueType (Rep dt) ~ ToT dt) Source #
data MyCompoundType Source #
Instances
Generic MyCompoundType Source # | |
Defined in Michelson.Typed.Haskell.Instr.Sum type Rep MyCompoundType :: Type -> Type # from :: MyCompoundType -> Rep MyCompoundType x # to :: Rep MyCompoundType x -> MyCompoundType # | |
IsoValue MyCompoundType Source # | |
Defined in Michelson.Typed.Haskell.Instr.Sum type ToT MyCompoundType :: T Source # toVal :: MyCompoundType -> Value (ToT MyCompoundType) Source # fromVal :: Value (ToT MyCompoundType) -> MyCompoundType Source # | |
type Rep MyCompoundType Source # | |
Defined in Michelson.Typed.Haskell.Instr.Sum | |
type ToT MyCompoundType Source # | |
Defined in Michelson.Typed.Haskell.Instr.Sum |
type InstrWrapC dt name = (IsoValue dt, Generic dt, GInstrWrap (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)), GValueType (Rep dt) ~ ToT dt) Source #
type CtorOnlyField name dt = RequireOneField name (GetCtorField dt name) Source #
Expect referred constructor to have only one field (otherwise compile error is raised) and extract its type.
type CtorHasOnlyField ctor dt f = GetCtorField dt ctor ~ OneField f Source #
Expect referred constructor to have only one field (in form of constraint) and extract its type.
type GetCtorField dt ctor = LnrFieldType (GetNamed ctor dt) Source #
Get type of constructor fields (one or zero) referred by given datatype and name.
type AppendCtorFieldAxiom (cf :: CtorField) (st :: [Type]) = ToTs (AppendCtorField cf st) ~ AppendCtorField cf (ToTs st) Source #
To use AppendCtorField
not only here for T
-based stacks, but also
later in Lorentz with Type
-based stacks we need the following property.
type family AppendCtorField (cf :: CtorField) (l :: [k]) :: [k] where ... Source #
Push field to stack, if any.
AppendCtorField (OneField t) (l :: [T]) = ToT t ': l | |
AppendCtorField (OneField t) (l :: [Type]) = t ': l | |
AppendCtorField NoFields (l :: [T]) = l | |
AppendCtorField NoFields (l :: [Type]) = l |
type family ExtractCtorField (cf :: CtorField) where ... Source #
Get something as field of the given constructor.
ExtractCtorField (OneField t) = t | |
ExtractCtorField NoFields = () |
We support only two scenarious - constructor with one field and without fields. Nonetheless, it's not that sad since for sum types we can't even assign names to fields if there are many (the style guide prohibits partial records).
appendCtorFieldAxiom :: (AppendCtorFieldAxiom (OneField Word) '[Int], AppendCtorFieldAxiom NoFields '[Int]) => Dict (AppendCtorFieldAxiom cf st) Source #
Proof of AppendCtorFieldAxiom
.
instrWrap :: forall dt name st. InstrWrapC dt name => Label name -> Instr (AppendCtorField (GetCtorField dt name) st) (ToT dt ': st) Source #
Wrap given element into a constructor with the given name.
Mentioned constructor must have only one field.
Since labels interpretable by OverloadedLabels extension cannot start with capital latter, prepend constructor name with letter "c" (see examples below).
hsWrap :: forall dt name. InstrWrapC dt name => Label name -> ExtractCtorField (GetCtorField dt name) -> dt Source #
Wrap a haskell value into a constructor with the given name.
This is symmetric to instrWrap
.
instrCase :: forall dt out inp. InstrCaseC dt inp out => Rec (CaseClause inp out) (CaseClauses dt) -> Instr (ToT dt ': inp) out Source #
Pattern-match on the given datatype.
(//->) :: Label ("c" `AppendSymbol` ctor) -> Instr (AppendCtorField x inp) out -> CaseClause inp out (CaseClauseParam ctor x) infixr 8 Source #
Lift an instruction to case clause.
You should write out constructor name corresponding to the clause explicitly. Prefix constructor name with "c" letter, otherwise your label will not be recognized by Haskell parser. Passing constructor name can be circumvented but doing so is not recomended as mentioning contructor name improves readability and allows avoiding some mistakes.
instrUnwrapUnsafe :: forall dt name st. InstrUnwrapC dt name => Label name -> Instr (ToT dt ': st) (ToT (CtorOnlyField name dt) ': st) Source #
Unwrap a constructor with the given name.
Rules which apply to instrWrap
function work here as well.
Although, unlike instrWrap
, this function does not work for nullary
constructors.
hsUnwrap :: forall dt name. InstrUnwrapC dt name => Label name -> dt -> Maybe (CtorOnlyField name dt) Source #
Try to unwrap a constructor with the given name.