Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Haskell-Michelson conversions.
Synopsis
- data Dict a where
- type Path = [Branch]
- data Branch
- ligoLayout :: GenericStrategy
- ligoCombLayout :: GenericStrategy
- type FieldDescriptions = [(Symbol, (Maybe Symbol, [(Symbol, Symbol)]))]
- class IsoValuesStack (ts :: [Type]) where
- type family ToTs' t where ...
- type family ToTs (ts :: [Type]) :: [T] where ...
- type GenericIsoValue t = (IsoValue t, Generic t, ToT t ~ GValueType (Rep t))
- class ToBigMap m where
- type ToBigMapKey m
- type ToBigMapValue m
- mkBigMap :: m -> BigMap (ToBigMapKey m) (ToBigMapValue m)
- data BigMap k v
- newtype BigMapId k v = BigMapId {}
- data Ticket (arg :: Type) = Ticket {}
- data ContractRef (arg :: Type) = ContractRef {
- crAddress :: Address
- crEntrypoint :: SomeEntrypointCall arg
- type HasNoOpToT a = (IsoValue a, ForbidOp (ToT a))
- type WellTypedToT a = (IsoValue a, WellTyped (ToT a))
- type SomeEntrypointCall arg = SomeEntrypointCallT (ToT arg)
- type EntrypointCall param arg = EntrypointCallT (ToT param) (ToT arg)
- type family ToT' t where ...
- class WellTypedToT a => IsoValue a where
- type KnownIsoT a = (IsoValue a, SingI (ToT a))
- isoValue :: (IsoValue a, IsoValue b) => Iso (Value (ToT a)) (Value (ToT b)) a b
- coerceContractRef :: ToT a ~ ToT b => ContractRef a -> ContractRef b
- contractRefToAddr :: ContractRef cp -> EpAddress
- totsKnownLemma :: forall s. KnownList s :- KnownList (ToTs s)
- totsAppendLemma :: forall a b. KnownList a => Dict (ToTs (a ++ b) ~ (ToTs a ++ ToTs b))
- type InstrUnwrapC dt name = (GenericIsoValue dt, GInstrUnwrap (Rep dt) (LnrBranch (GetNamed name dt)) (CtorOnlyField name dt))
- type family GCaseBranchInput ctor x :: CaseClauseParam
- type family GCaseBranchInput ctor x :: CaseClauseParam
- type family GCaseClauses x rest :: [CaseClauseParam]
- type family GCaseClauses x rest :: [CaseClauseParam]
- type CaseClauses a = GCaseClauses (Rep a) '[]
- data CaseClause (inp :: [T]) (out :: [T]) (param :: CaseClauseParam) where
- CaseClause :: RemFail Instr (AppendCtorField x inp) out -> CaseClause inp out ('CaseClauseParam ctor x)
- data CaseClauseParam = CaseClauseParam Symbol CtorField
- type InstrCaseC dt = (GenericIsoValue dt, GInstrCase (Rep dt) '[])
- data MyCompoundType
- type InstrWrapOneC dt name = (InstrWrapC dt name, GetCtorField dt name ~ 'OneField (CtorOnlyField name dt))
- type InstrWrapC dt name = (GenericIsoValue dt, GInstrWrap (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name 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 family IsPrimitiveValue (x :: Type) :: Bool where ...
- type AppendCtorFieldAxiom (cf :: CtorField) (st :: [Type]) = ToTs (AppendCtorField cf st) ~ AppendCtorField cf (ToTs st)
- type family AppendCtorField cf l 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)
- instrWrapOne :: forall dt name st. InstrWrapOneC dt name => Label name -> Instr (ToT (CtorOnlyField name dt) ': 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 => Rec (CaseClause inp out) (CaseClauses dt) -> RemFail Instr (ToT dt ': inp) out
- (//->) :: Label ("c" `AppendSymbol` ctor) -> RemFail Instr (AppendCtorField x inp) out -> CaseClause inp out ('CaseClauseParam ctor x)
- unsafeInstrUnwrap :: 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)
- type InstrDeconstructC dt st = (GenericIsoValue dt, GInstrDeconstruct (Rep dt) '[] st)
- type family GFieldTypes x rest :: [Type]
- type family GFieldTypes x rest :: [Type]
- type InstrConstructC dt = (GenericIsoValue dt, GInstrConstruct (Rep dt) '[])
- type ConstructorFieldNames dt = GFieldNames (Rep dt)
- type ConstructorFieldTypes dt = GFieldTypes (Rep dt) '[]
- class ToTs xs ~ ToTs ys => CastFieldConstructors xs ys where
- castFieldConstructorsImpl :: Rec (FieldConstructor st) xs -> Rec (FieldConstructor st) ys
- newtype FieldConstructor (st :: [k]) (field :: Type) = FieldConstructor (Instr (ToTs' st) (ToT field ': ToTs' st))
- type InstrSetFieldC dt name = (GenericIsoValue dt, GInstrSetField name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)))
- type InstrGetFieldC dt name = (GenericIsoValue dt, GInstrGet name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt)))
- type GetFieldType dt name = LnrFieldType (GetNamed name dt)
- type family GLookupNamed (name :: Symbol) (x :: Type -> Type) :: Maybe LookupNamedResult where ...
- instrToField :: forall dt name st. InstrGetFieldC dt name => Label name -> Instr (ToT dt ': st) (ToT (GetFieldType dt name) ': st)
- instrGetField :: forall dt name st. (InstrGetFieldC dt name, DupableScope (ToT (GetFieldType dt name))) => Label name -> Instr (ToT dt ': st) (ToT (GetFieldType dt name) ': (ToT dt ': st))
- instrGetFieldOpen :: forall dt name res st. InstrGetFieldC dt name => Instr '[ToT (GetFieldType dt name)] '[res, ToT (GetFieldType dt name)] -> Instr '[ToT (GetFieldType dt name)] '[res] -> Label name -> Instr (ToT dt ': st) (res ': (ToT dt ': st))
- instrSetField :: forall dt name st. InstrSetFieldC dt name => Label name -> Instr (ToT (GetFieldType dt name) ': (ToT dt ': st)) (ToT dt ': st)
- instrSetFieldOpen :: forall dt name new st. InstrSetFieldC dt name => Instr '[new, ToT (GetFieldType dt name)] '[ToT (GetFieldType dt name)] -> Label name -> Instr (new ': (ToT dt ': st)) (ToT dt ': st)
- instrConstruct :: forall dt st. InstrConstructC dt => Rec (FieldConstructor st) (ConstructorFieldTypes dt) -> Instr st (ToT dt ': st)
- instrConstructStack :: forall dt stack st. (InstrConstructC dt, stack ~ ToTs (ConstructorFieldTypes dt)) => Instr (stack ++ st) (ToT dt ': st)
- instrDeconstruct :: forall dt stack (st :: [T]). (InstrDeconstructC dt st, stack ~ ToTs (GFieldTypes (Rep dt) '[])) => Instr (ToT dt ': st) (stack ++ st)
- type LooseSumC dt = (Generic dt, GLooseSum (Rep dt))
- data ComposeResult a
- toTaggedVal :: LooseSumC dt => dt -> (Text, SomeValue)
- fromTaggedVal :: LooseSumC dt => (Text, SomeValue) -> ComposeResult dt
- data FieldRep a = FieldRep {}
- data ConstructorRep a = ConstructorRep {}
- type ADTRep a = [ConstructorRep a]
- crDescriptionL :: forall a. Lens' (ConstructorRep a) (Maybe Text)
- crFieldsL :: forall a a. Lens (ConstructorRep a) (ConstructorRep a) [FieldRep a] [FieldRep a]
- crNameL :: forall a. Lens' (ConstructorRep a) Text
- type PolyTypeHasDocC ts = Each '[TypeHasDoc] ts
- class GProductHasDoc (x :: Type -> Type)
- class GTypeHasDoc (x :: Type -> Type)
- class IsHomomorphic a
- class HaveCommonTypeCtor a b
- newtype DStorageType = DStorageType DType
- data DType where
- DType :: TypeHasDoc a => Proxy a -> DType
- data SomeTypeWithDoc where
- SomeTypeWithDoc :: TypeHasDoc td => Proxy td -> SomeTypeWithDoc
- type TypeDocMichelsonRep a = Proxy a -> (Maybe DocTypeRepLHS, T)
- type TypeDocHaskellRep a = Proxy a -> FieldDescriptionsV -> Maybe (Maybe DocTypeRepLHS, ADTRep SomeTypeWithDoc)
- class (Typeable a, SingI (TypeDocFieldDescriptions a), FieldDescriptionsValid (TypeDocFieldDescriptions a) a) => TypeHasDoc a where
- type TypeDocFieldDescriptions a :: FieldDescriptions
- typeDocName :: Proxy a -> Text
- typeDocMdDescription :: Markdown
- typeDocMdReference :: Proxy a -> WithinParens -> Markdown
- typeDocDependencies :: Proxy a -> [SomeDocDefinitionItem]
- typeDocHaskellRep :: TypeDocHaskellRep a
- typeDocMichelsonRep :: TypeDocMichelsonRep a
- data FieldSnakeCase
- data FieldCamelCase
- class TypeHasFieldNamingStrategy a where
- typeFieldNamingStrategy :: Text -> Text
- newtype WithinParens = WithinParens Bool
- frDescriptionL :: forall a. Lens' (FieldRep a) (Maybe Text)
- frNameL :: forall a. Lens' (FieldRep a) (Maybe Text)
- frTypeRepL :: forall a a. Lens (FieldRep a) (FieldRep a) a a
- buildADTRep :: forall a. (WithinParens -> a -> Markdown) -> ADTRep a -> Markdown
- applyWithinParens :: WithinParens -> Markdown -> Markdown
- buildTypeWithinParens :: forall a. Typeable a => WithinParens -> Markdown
- typeDocBuiltMichelsonRep :: TypeHasDoc a => Proxy a -> Doc
- dTypeDep :: forall (t :: Type). TypeHasDoc t => SomeDocDefinitionItem
- dTypeDepP :: forall (t :: Type). TypeHasDoc t => Proxy t -> SomeDocDefinitionItem
- dStorage :: forall store. TypeHasDoc store => DStorageType
- customTypeDocMdReference :: (Text, DType) -> [DType] -> WithinParens -> Markdown
- customTypeDocMdReference' :: (Text, DType) -> [WithinParens -> Markdown] -> WithinParens -> Markdown
- homomorphicTypeDocMdReference :: forall (t :: Type). (Typeable t, TypeHasDoc t, IsHomomorphic t) => Proxy t -> WithinParens -> Markdown
- poly1TypeDocMdReference :: forall t (r :: Type) (a :: Type). (r ~ t a, Typeable t, Each '[TypeHasDoc] [r, a], IsHomomorphic t) => Proxy r -> WithinParens -> Markdown
- poly2TypeDocMdReference :: forall t (r :: Type) (a :: Type) (b :: Type). (r ~ t a b, Typeable t, Each '[TypeHasDoc] [r, a, b], IsHomomorphic t) => Proxy r -> WithinParens -> Markdown
- genericTypeDocDependencies :: forall a. (Generic a, GTypeHasDoc (Rep a)) => Proxy a -> [SomeDocDefinitionItem]
- homomorphicTypeDocHaskellRep :: forall a. (Generic a, GTypeHasDoc (Rep a)) => TypeDocHaskellRep a
- concreteTypeDocHaskellRep :: forall a b. (Typeable a, GenericIsoValue a, GTypeHasDoc (Rep a), HaveCommonTypeCtor b a) => TypeDocHaskellRep b
- unsafeConcreteTypeDocHaskellRep :: forall a b. (Typeable a, GenericIsoValue a, GTypeHasDoc (Rep a)) => TypeDocHaskellRep b
- haskellRepNoFields :: TypeDocHaskellRep a -> TypeDocHaskellRep a
- haskellRepMap :: (Text -> Text) -> TypeDocHaskellRep a -> TypeDocHaskellRep a
- haskellAddNewtypeField :: Text -> TypeDocHaskellRep a -> TypeDocHaskellRep a
- haskellRepAdjust :: (Maybe Text -> Maybe Text) -> TypeDocHaskellRep a -> TypeDocHaskellRep a
- homomorphicTypeDocMichelsonRep :: forall a. KnownIsoT a => TypeDocMichelsonRep a
- concreteTypeDocMichelsonRep :: forall a b. (Typeable a, KnownIsoT a, HaveCommonTypeCtor b a) => TypeDocMichelsonRep b
- unsafeConcreteTypeDocMichelsonRep :: forall a b. (Typeable a, KnownIsoT a) => TypeDocMichelsonRep b
Documentation
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) | |
Path to a leaf (some field or constructor) in generic tree representation.
Which branch to choose in generic tree representation: left,
straight or right. S
is used when there is one constructor with
one field (something newtype-like).
The reason why we need S
can be explained by this example:
data A = A1 B | A2 Integer
data B = B Bool
Now we may search for A1 constructor or B constructor. Without S
in
both cases path will be the same ([L]).
ligoLayout :: GenericStrategy Source #
Default layout in LIGO.
To be used with customGeneric
, see this method for more info.
This is similar to leftBalanced
, but
- fields are sorted alphabetically;
- always puts as large complete binary subtrees as possible at left.
ligoCombLayout :: GenericStrategy Source #
Comb layout in LIGO ( [@layout:comb]
).
To be used with customGeneric
.
Note: to make comb layout work for sum types, make sure that in LIGO all the constructors are preceded by the bar symbol in your type declaration:
type my_type = [@layout:comb] | Ctor1 of nat ← bar symbol _must_ be here | Ctor2 of int ...
Though the situation may change: https://gitlab.com/ligolang/ligo/-/issues/1104.
type FieldDescriptions = [(Symbol, (Maybe Symbol, [(Symbol, Symbol)]))] Source #
Description of constructors and fields of some datatype.
This type is just two nested maps represented as associative lists. It is supposed to be interpreted like this:
[(Constructor name, (Maybe constructor description, [(Field name, Field description)]))]
Example with a concrete data type:
data Foo = Foo { fFoo :: Int } | Bar { fBar :: Text } deriving (Generic) type FooDescriptions = '[ '( "Foo", '( 'Just "foo constructor", , '[ '("fFoo", "some number") ]) ) , '( "Bar", '( 'Nothing, , '[ '("fBar", "some string") ]) ) ]
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 # | |
type family ToTs (ts :: [Type]) :: [T] where ... Source #
Type function to convert a Haskell stack type to T
-based one.
type GenericIsoValue t = (IsoValue t, Generic t, ToT t ~ GValueType (Rep t)) Source #
Whether Michelson representation of the type is derived via Generics.
class ToBigMap m where Source #
type ToBigMapKey m Source #
type ToBigMapValue m Source #
mkBigMap :: m -> BigMap (ToBigMapKey m) (ToBigMapValue m) Source #
Instances
Instances
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 # | |
IsoValue (BigMapId k2 v) Source # | |
Buildable (BigMapId k2 v) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value | |
type ToT (BigMapId k2 v) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Value |
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 |
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
type SomeEntrypointCall arg = SomeEntrypointCallT (ToT arg) Source #
type EntrypointCall param arg = EntrypointCallT (ToT param) (ToT arg) Source #
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.
coerceContractRef :: ToT a ~ ToT b => ContractRef a -> ContractRef b Source #
Replace type argument of ContractRef
with isomorphic one.
contractRefToAddr :: ContractRef cp -> EpAddress Source #
type InstrUnwrapC dt name = (GenericIsoValue dt, GInstrUnwrap (Rep dt) (LnrBranch (GetNamed name dt)) (CtorOnlyField name dt)) Source #
type family GCaseBranchInput ctor x :: CaseClauseParam Source #
Instances
type GCaseBranchInput ctor (U1 :: Type -> Type) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseBranchInput ctor (Rec0 a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseBranchInput ctor (x :*: y) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseBranchInput ctor (S1 i x) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum |
type family GCaseBranchInput ctor x :: CaseClauseParam Source #
Instances
type GCaseBranchInput ctor (U1 :: Type -> Type) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseBranchInput ctor (Rec0 a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseBranchInput ctor (x :*: y) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseBranchInput ctor (S1 i x) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum |
type family GCaseClauses x rest :: [CaseClauseParam] Source #
Instances
type GCaseClauses (V1 :: Type -> Type) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseClauses (x :+: y) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseClauses (C1 ('MetaCons ctor _1 _2) x) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseClauses (D1 i x) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum |
type family GCaseClauses x rest :: [CaseClauseParam] Source #
Instances
type GCaseClauses (V1 :: Type -> Type) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseClauses (x :+: y) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseClauses (C1 ('MetaCons ctor _1 _2) x) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum | |
type GCaseClauses (D1 i x) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum |
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 :: RemFail 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 = (GenericIsoValue dt, GInstrCase (Rep dt) '[]) Source #
data MyCompoundType Source #
Instances
Generic MyCompoundType Source # | |
Defined in Morley.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 Morley.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 Morley.Michelson.Typed.Haskell.Instr.Sum | |
type ToT MyCompoundType Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Sum |
type InstrWrapOneC dt name = (InstrWrapC dt name, GetCtorField dt name ~ 'OneField (CtorOnlyField name dt)) Source #
type InstrWrapC dt name = (GenericIsoValue dt, GInstrWrap (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name 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 family IsPrimitiveValue (x :: Type) :: Bool where ... Source #
Whether given type represents an atomic Michelson value.
IsPrimitiveValue (Maybe _) = 'True | |
IsPrimitiveValue (NamedF _ _ _) = 'True | |
IsPrimitiveValue Integer = 'True | |
IsPrimitiveValue Natural = 'True | |
IsPrimitiveValue Text = 'True | |
IsPrimitiveValue MText = 'True | |
IsPrimitiveValue Bool = 'True | |
IsPrimitiveValue ByteString = 'True | |
IsPrimitiveValue Mutez = 'True | |
IsPrimitiveValue Address = 'True | |
IsPrimitiveValue EpAddress = 'True | |
IsPrimitiveValue KeyHash = 'True | |
IsPrimitiveValue Timestamp = 'True | |
IsPrimitiveValue PublicKey = 'True | |
IsPrimitiveValue Signature = 'True | |
IsPrimitiveValue (ContractRef _) = 'True | |
IsPrimitiveValue (BigMap _ _) = 'True | |
IsPrimitiveValue (Map _ _) = 'True | |
IsPrimitiveValue (Set _) = 'True | |
IsPrimitiveValue [_] = 'True | |
IsPrimitiveValue (Operation' _) = 'True | |
IsPrimitiveValue ChainId = 'True | |
IsPrimitiveValue _ = 'False |
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 l 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).
instrWrapOne :: forall dt name st. InstrWrapOneC dt name => Label name -> Instr (ToT (CtorOnlyField name dt) ': st) (ToT dt ': st) Source #
Like instrWrap
but only works for contructors with a single field.
Results in a type error if a constructor with no field is used instead.
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 => Rec (CaseClause inp out) (CaseClauses dt) -> RemFail Instr (ToT dt ': inp) out Source #
Pattern-match on the given datatype.
(//->) :: Label ("c" `AppendSymbol` ctor) -> RemFail 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.
unsafeInstrUnwrap :: 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.
type InstrDeconstructC dt st = (GenericIsoValue dt, GInstrDeconstruct (Rep dt) '[] st) Source #
Constraint for instrConstruct
.
type family GFieldTypes x rest :: [Type] Source #
Instances
type GFieldTypes (U1 :: Type -> Type) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (V1 :: Type -> Type) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (Rec0 a) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (x :*: y) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (x :+: y) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (M1 t i x) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product |
type family GFieldTypes x rest :: [Type] Source #
Instances
type GFieldTypes (U1 :: Type -> Type) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (V1 :: Type -> Type) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (Rec0 a) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (x :*: y) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (x :+: y) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product | |
type GFieldTypes (M1 t i x) rest Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product |
type InstrConstructC dt = (GenericIsoValue dt, GInstrConstruct (Rep dt) '[]) Source #
Constraint for instrConstruct
and gInstrConstructStack
.
type ConstructorFieldNames dt = GFieldNames (Rep dt) Source #
Names of all fields in a datatype.
type ConstructorFieldTypes dt = GFieldTypes (Rep dt) '[] Source #
Types of all fields in a datatype.
class ToTs xs ~ ToTs ys => CastFieldConstructors xs ys where Source #
Ability to pass list of fields with the same ToTs. It may be useful if you don't want to work with NamedF in ConstructorFieldTypes.
castFieldConstructorsImpl :: Rec (FieldConstructor st) xs -> Rec (FieldConstructor st) ys Source #
Instances
CastFieldConstructors ('[] :: [Type]) ('[] :: [Type]) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product castFieldConstructorsImpl :: forall {k} (st :: [k]). Rec (FieldConstructor st) '[] -> Rec (FieldConstructor st) '[] Source # | |
(CastFieldConstructors xs ys, ToTs xs ~ ToTs ys, ToT x ~ ToT y) => CastFieldConstructors (x ': xs) (y ': ys) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Instr.Product castFieldConstructorsImpl :: forall {k} (st :: [k]). Rec (FieldConstructor st) (x ': xs) -> Rec (FieldConstructor st) (y ': ys) Source # |
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 = (GenericIsoValue dt, GInstrSetField name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name dt))) Source #
Constraint for instrSetField
.
type InstrGetFieldC dt name = (GenericIsoValue dt, GInstrGet name (Rep dt) (LnrBranch (GetNamed name dt)) (LnrFieldType (GetNamed name 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.
type family GLookupNamed (name :: Symbol) (x :: Type -> Type) :: Maybe LookupNamedResult where ... Source #
GLookupNamed name (D1 _ x) = GLookupNamed name x | |
GLookupNamed name (C1 _ x) = GLookupNamed name x | |
GLookupNamed name (S1 ('MetaSel ('Just recName) _ _ _) (Rec0 a)) = If (name == recName) ('Just $ 'LNR a '[]) 'Nothing | |
GLookupNamed name (S1 _ (Rec0 (NamedF f a fieldName))) = If (name == fieldName) ('Just $ 'LNR (NamedInner (NamedF f a fieldName)) '[]) 'Nothing | |
GLookupNamed _ (S1 _ _) = 'Nothing | |
GLookupNamed name (x :*: y) = LNMergeFound name (GLookupNamed name x) (GLookupNamed name y) | |
GLookupNamed name (_ :+: _) = TypeError (('Text "Cannot seek for a field " :<>: 'ShowType name) :<>: 'Text " in sum type") | |
GLookupNamed _ U1 = 'Nothing | |
GLookupNamed _ V1 = TypeError ('Text "Cannot access fields of void-like type") |
instrToField :: 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.
instrGetField :: forall dt name st. (InstrGetFieldC dt name, DupableScope (ToT (GetFieldType dt name))) => Label name -> Instr (ToT dt ': st) (ToT (GetFieldType dt name) ': (ToT dt ': st)) Source #
Make an instruction which copies given field of the given datatype.
This behaves exactly as Seq DUP (instrToField #name)
, but does not require
the entire datatype to be dupable (the field ofc still must be dupable).
If we follow the path from the root to the copied field in the pairs tree, the more nodes contain non-dupable elements in the subtree, the less efficient this function becomes. Assuming that all fields are accessed equally often, the most optimal representation would be to put all dupable elements to one subtree of the root, and all non-dupable elements in the second subtree of the root.
instrGetFieldOpen :: forall dt name res st. InstrGetFieldC dt name => Instr '[ToT (GetFieldType dt name)] '[res, ToT (GetFieldType dt name)] -> Instr '[ToT (GetFieldType dt name)] '[res] -> Label name -> Instr (ToT dt ': st) (res ': (ToT dt ': st)) Source #
"Open" version of instrGetField
, meaning that it accepts
continuations that accept the copied field. This allows chaining
getters without requiring DupableScope
on the intermediate fields.
Accepted continuations:
- The one that leaves the field on stack (and does a duplication inside). Used when the datatype had an unfortunate placement of non-dupable fields, or the intermediate field contains non-dupable elements, so the duplication cannot occur automatically in between.
- The one that consumes the field, used in case we managed to call
DUP
earlier to make the instruction's implementation smaller, and now we only need to access the field withCAR
andCDR
s.
Note that only one continuation will be chosen eventually, no contract size overhead is expected in this regard.
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.
instrSetFieldOpen :: forall dt name new st. InstrSetFieldC dt name => Instr '[new, ToT (GetFieldType dt name)] '[ToT (GetFieldType dt name)] -> Label name -> Instr (new ': (ToT dt ': st)) (ToT dt ': st) Source #
"Open" version of instrSetField
, meaning that it accepts a continuation
that describes how to update the field. This allows chaining setters with
zero overhead and without requiring DupableScope
on the intermediate fields
(if we supported only closed setters that work directly with one datatype, we
would need to duplicate intermediate fields to chain setters).
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.
instrConstructStack :: forall dt stack st. (InstrConstructC dt, stack ~ ToTs (ConstructorFieldTypes dt)) => Instr (stack ++ st) (ToT dt ': st) Source #
instrDeconstruct :: forall dt stack (st :: [T]). (InstrDeconstructC dt st, stack ~ ToTs (GFieldTypes (Rep dt) '[])) => Instr (ToT dt ': st) (stack ++ st) Source #
For given complex type dt
deconstruct it to its field types.
type LooseSumC dt = (Generic dt, GLooseSum (Rep dt)) Source #
Constraint for toTaggedVal
and fromTaggedVal
.
data ComposeResult a Source #
Possible outcomes of an attempt to construct a Haskell ADT value from constructor name and relevant data.
ComposeOk a | Composed fine. |
ComposeCtorNotFound | No constructor with such name. |
ComposeFieldTypeMismatch T T | Found required constructor, but type of data does not correspond to provided one. |
Instances
Functor ComposeResult Source # | |
Defined in Morley.Michelson.Typed.Haskell.LooseSum fmap :: (a -> b) -> ComposeResult a -> ComposeResult b # (<$) :: a -> ComposeResult b -> ComposeResult a # | |
Monoid (ComposeResult a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.LooseSum mempty :: ComposeResult a # mappend :: ComposeResult a -> ComposeResult a -> ComposeResult a # mconcat :: [ComposeResult a] -> ComposeResult a # | |
Semigroup (ComposeResult a) Source # | |
Defined in Morley.Michelson.Typed.Haskell.LooseSum (<>) :: ComposeResult a -> ComposeResult a -> ComposeResult a # sconcat :: NonEmpty (ComposeResult a) -> ComposeResult a # stimes :: Integral b => b -> ComposeResult a -> ComposeResult a # |
toTaggedVal :: LooseSumC dt => dt -> (Text, SomeValue) Source #
Decompose Haskell type into constructor name and
data it carries, converting the latter into Michelson Value
.
fromTaggedVal :: LooseSumC dt => (Text, SomeValue) -> ComposeResult dt Source #
Inverse to toTaggedVal
.
Representation of a field with an optional description.
data ConstructorRep a Source #
Representation of a constructor with an optional description.
type ADTRep a = [ConstructorRep a] Source #
Stands for representation of some Haskell ADT corresponding to
Michelson value. Type parameter a
is what you put in place of
each field of the datatype, e.g. information about field type.
This representation also includes descriptions of constructors and fields.
crDescriptionL :: forall a. Lens' (ConstructorRep a) (Maybe Text) Source #
crFieldsL :: forall a a. Lens (ConstructorRep a) (ConstructorRep a) [FieldRep a] [FieldRep a] Source #
type PolyTypeHasDocC ts = Each '[TypeHasDoc] ts Source #
Constraint, required when deriving TypeHasDoc
for polymorphic type
with the least possible number of methods defined manually.
class GProductHasDoc (x :: Type -> Type) Source #
Product type traversal for TypeHasDoc
.
gProductDocHaskellRep
Instances
GProductHasDoc (U1 :: Type -> Type) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc gProductDocHaskellRep :: [(Text, Text)] -> [FieldRep SomeTypeWithDoc] | |
(GProductHasDoc x, GProductHasDoc y) => GProductHasDoc (x :*: y) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc gProductDocHaskellRep :: [(Text, Text)] -> [FieldRep SomeTypeWithDoc] | |
(TypeHasDoc a, KnownSymbol field) => GProductHasDoc (S1 ('MetaSel ('Just field) _1 _2 _3) (Rec0 a)) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc gProductDocHaskellRep :: [(Text, Text)] -> [FieldRep SomeTypeWithDoc] | |
TypeHasDoc a => GProductHasDoc (S1 ('MetaSel ('Nothing :: Maybe Symbol) _1 _2 _3) (Rec0 a)) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc gProductDocHaskellRep :: [(Text, Text)] -> [FieldRep SomeTypeWithDoc] |
class GTypeHasDoc (x :: Type -> Type) Source #
Generic traversal for automatic deriving of some methods in TypeHasDoc
.
gTypeDocHaskellRep
Instances
GTypeHasDoc (V1 :: Type -> Type) Source # | |
(GTypeHasDoc x, GTypeHasDoc y) => GTypeHasDoc (x :+: y) Source # | |
(GProductHasDoc x, KnownSymbol ctor) => GTypeHasDoc (C1 ('MetaCons ctor _1 _2) x) Source # | |
GTypeHasDoc x => GTypeHasDoc (D1 ('MetaData _a _b _c 'False) x) Source # | |
GTypeHasDoc x => GTypeHasDoc (D1 ('MetaData _a _b _c 'True) x) Source # | |
class IsHomomorphic a Source #
Require this type to be homomorphic.
Instances
IsHomomorphic (a :: k) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
(TypeError ('Text "Type is not homomorphic: " :<>: 'ShowType (a b)) :: Constraint) => IsHomomorphic (a b :: k2) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc |
class HaveCommonTypeCtor a b Source #
Require two types to be built from the same type constructor.
E.g. HaveCommonTypeCtor (Maybe Integer) (Maybe Natural)
is defined,
while HaveCmmonTypeCtor (Maybe Integer) [Integer]
is not.
Instances
HaveCommonTypeCtor (a :: k) (a :: k) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
HaveCommonTypeCtor ac bc => HaveCommonTypeCtor (ac a :: k2) (bc b :: k4) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc |
newtype DStorageType Source #
Doc element with description of contract storage type.
Instances
Doc element with description of a type.
DType :: TypeHasDoc a => Proxy a -> DType |
Instances
Eq DType Source # | |
Ord DType Source # | |
DocItem DType Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc type DocItemPlacement DType :: DocItemPlacementKind Source # type DocItemReferenced DType :: DocItemReferencedKind Source # docItemPos :: Natural Source # docItemSectionName :: Maybe Text Source # docItemSectionDescription :: Maybe Markdown Source # docItemSectionNameStyle :: DocSectionNameStyle Source # docItemRef :: DType -> DocItemRef (DocItemPlacement DType) (DocItemReferenced DType) Source # docItemToMarkdown :: HeaderLevel -> DType -> Markdown Source # docItemToToc :: HeaderLevel -> DType -> Markdown Source # docItemDependencies :: DType -> [SomeDocDefinitionItem] Source # docItemsOrder :: [DType] -> [DType] Source # | |
Buildable DType Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
type DocItemPlacement DType Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc | |
type DocItemReferenced DType Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc |
data SomeTypeWithDoc where Source #
Data hides some type implementing TypeHasDoc
.
SomeTypeWithDoc :: TypeHasDoc td => Proxy td -> SomeTypeWithDoc |
type TypeDocMichelsonRep a = Proxy a -> (Maybe DocTypeRepLHS, T) Source #
Signature of typeDocMichelsonRep
function.
As in TypeDocHaskellRep
, set the first element of the pair to Nothing
for primitive types, otherwise it stands as some instantiation of a type,
and its Michelson representation is given in the second element of the pair.
Examples of rendered representation:
pair int nat
- for homomorphic type.MyError Integer = pair string int
- concrete sample for polymorphic type.
type TypeDocHaskellRep a = Proxy a -> FieldDescriptionsV -> Maybe (Maybe DocTypeRepLHS, ADTRep SomeTypeWithDoc) Source #
Signature of typeDocHaskellRep
function.
A value of FieldDescriptionsV
is provided by the library to make sure that
instances won't replace it with an unchecked value.
When value is Just
, it contains types which this type is built from.
First element of provided pair may contain name a concrete type which has
the same type constructor as a
(or just a
for homomorphic types), and
the second element of the pair - its unfolding in Haskell.
For example, for some newtype MyNewtype = MyNewtype (Integer, Natural)
we would not specify the first element in the pair because MyNewtype
is
already a concrete type, and second element would contain (Integer, Natural)
.
For polymorphic types like newtype MyPolyNewtype a = MyPolyNewtype (Text, a)
,
we want to describe its representation on some example of a
, because
working with type variables is too non-trivial; so the first element of
the pair may be e.g. "MyPolyNewType Integer"
, and the second one shows
that it unfolds to (Text, Integer)
.
When rendered, values of this type look like:
(Integer, Natural)
- for homomorphic type.MyError Integer = (Text, Integer)
- concrete sample for polymorphic type.
class (Typeable a, SingI (TypeDocFieldDescriptions a), FieldDescriptionsValid (TypeDocFieldDescriptions a) a) => TypeHasDoc a where Source #
Description for a Haskell type appearing in documentation.
type TypeDocFieldDescriptions a :: FieldDescriptions Source #
Description of constructors and fields of a
.
See FieldDescriptions
documentation for an example of usage.
Descriptions will be checked at compile time to make sure that only existing constructors and fields are referenced.
For that check to work instance Generic a
is required whenever TypeDocFieldDescriptions
is not empty.
For implementation of the check see FieldDescriptionsValid
type family.
type TypeDocFieldDescriptions _ = '[]
typeDocName :: Proxy a -> Text Source #
Name of type as it appears in definitions section.
Each type must have its own unique name because it will be used in identifier for references.
Default definition derives name from Generics. If it does not fit, consider defining this function manually. (We tried using Data.Data for this, but it produces names including module names which is not do we want).
default typeDocName :: (Generic a, KnownSymbol (GenericTypeName a)) => Proxy a -> Text Source #
typeDocMdDescription :: Markdown Source #
Explanation of a type. Markdown formatting is allowed.
typeDocMdReference :: Proxy a -> WithinParens -> Markdown Source #
How reference to this type is rendered, in Markdown.
Examples:
[Integer](#type-integer)
,[Maybe](#type-Maybe) [()](#type-unit)
.
Consider using one of the following functions as default implementation; which one to use depends on number of type arguments in your type:
If none of them fits your purposes precisely, consider using
customTypeDocMdReference
.
default typeDocMdReference :: (Typeable a, IsHomomorphic a) => Proxy a -> WithinParens -> Markdown Source #
typeDocDependencies :: Proxy a -> [SomeDocDefinitionItem] Source #
All types which this type directly contains.
Used in automatic types discovery.
default typeDocDependencies :: (Generic a, GTypeHasDoc (Rep a)) => Proxy a -> [SomeDocDefinitionItem] Source #
typeDocHaskellRep :: TypeDocHaskellRep a Source #
For complex types - their immediate Haskell representation.
For primitive types set this to Nothing
.
For homomorphic types use homomorphicTypeDocHaskellRep
implementation.
For polymorphic types consider using concreteTypeDocHaskellRep
as implementation.
Modifier haskellRepNoFields
can be used to hide names of fields,
beneficial for newtypes.
Use haskellRepAdjust
or haskellRepMap
for more involved adjustments.
Also, consider defining an instance of TypeHasFieldNamingStrategy
instead
of defining this method -- the former can be used downstream, e.g. in
lorentz, for better naming consistency.
default typeDocHaskellRep :: (Generic a, GTypeHasDoc (Rep a), IsHomomorphic a, TypeHasFieldNamingStrategy a) => TypeDocHaskellRep a Source #
typeDocMichelsonRep :: TypeDocMichelsonRep a Source #
Final michelson representation of a type.
For homomorphic types use homomorphicTypeDocMichelsonRep
implementation.
For polymorphic types consider using concreteTypeDocMichelsonRep
as implementation.
default typeDocMichelsonRep :: (KnownIsoT a, IsHomomorphic a) => TypeDocMichelsonRep a Source #
Instances
data FieldSnakeCase Source #
Empty datatype used as marker for DerivingVia
with
TypeHasFieldNamingStrategy
.
Uses
strategy.toSnake
. dropPrefix
Instances
data FieldCamelCase Source #
Empty datatype used as marker for DerivingVia
with
TypeHasFieldNamingStrategy
.
Uses stripFieldPrefix
strategy.
Instances
class TypeHasFieldNamingStrategy a where Source #
Field naming strategy used by a type. id
by default.
Some common options include: > typeFieldNamingStrategy = stripFieldPrefix > typeFieldNamingStrategy = toSnake . dropPrefix
This is used by the default implementation of typeDocHaskellRep
and
intended to be reused downstream.
You can also use DerivingVia
together with FieldCamelCase
and
FieldSnakeCase
to easily define instances of this class:
data MyType = ... deriving TypeHasFieldNamingStrategy via FieldCamelCase
Nothing
typeFieldNamingStrategy :: Text -> Text Source #
Instances
TypeHasFieldNamingStrategy (a :: k) Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc typeFieldNamingStrategy :: Text -> Text Source # | |
TypeHasFieldNamingStrategy FieldCamelCase Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc typeFieldNamingStrategy :: Text -> Text Source # | |
TypeHasFieldNamingStrategy FieldSnakeCase Source # | |
Defined in Morley.Michelson.Typed.Haskell.Doc typeFieldNamingStrategy :: Text -> Text Source # |
newtype WithinParens Source #
Whether given text should be rendered grouped in parentheses (if they make sense).
buildADTRep :: forall a. (WithinParens -> a -> Markdown) -> ADTRep a -> Markdown Source #
Show given ADTRep
in a neat way.
applyWithinParens :: WithinParens -> Markdown -> Markdown Source #
buildTypeWithinParens :: forall a. Typeable a => WithinParens -> Markdown Source #
Show type, wrapping into parentheses if necessary.
typeDocBuiltMichelsonRep :: TypeHasDoc a => Proxy a -> Doc Source #
Fully render Michelson representation of a type.
Since this will be used in markdown, the type is forced to a single line.
>>>
data Foo = Foo () () () () () () () () () () () () deriving (Generic, IsoValue)
>>>
instance TypeHasDoc Foo where typeDocMdDescription = "Foo type"
>>>
typeDocBuiltMichelsonRep $ Proxy @Foo
**Final Michelson representation:** `pair (pair (pair unit unit unit) unit unit unit) (pair unit unit unit) unit unit unit`
dTypeDep :: forall (t :: Type). TypeHasDoc t => SomeDocDefinitionItem Source #
Create a DType
in form suitable for putting to typeDocDependencies
.
dTypeDepP :: forall (t :: Type). TypeHasDoc t => Proxy t -> SomeDocDefinitionItem Source #
Proxy version of dTypeDep
.
dStorage :: forall store. TypeHasDoc store => DStorageType Source #
Shortcut for DStorageType
.
customTypeDocMdReference :: (Text, DType) -> [DType] -> WithinParens -> Markdown Source #
Render a reference to a type which consists of type constructor (you have to provide name of this type constructor and documentation for the whole type) and zero or more type arguments.
customTypeDocMdReference' :: (Text, DType) -> [WithinParens -> Markdown] -> WithinParens -> Markdown Source #
More generic version of customTypeDocMdReference
, it accepts
arguments not as types with doc, but printers for them.
homomorphicTypeDocMdReference :: forall (t :: Type). (Typeable t, TypeHasDoc t, IsHomomorphic t) => Proxy t -> WithinParens -> Markdown Source #
Derive typeDocMdReference
, for homomorphic types only.
poly1TypeDocMdReference :: forall t (r :: Type) (a :: Type). (r ~ t a, Typeable t, Each '[TypeHasDoc] [r, a], IsHomomorphic t) => Proxy r -> WithinParens -> Markdown Source #
Derive typeDocMdReference
, for polymorphic type with one
type argument, like Maybe Integer
.
poly2TypeDocMdReference :: forall t (r :: Type) (a :: Type) (b :: Type). (r ~ t a b, Typeable t, Each '[TypeHasDoc] [r, a, b], IsHomomorphic t) => Proxy r -> WithinParens -> Markdown Source #
Derive typeDocMdReference
, for polymorphic type with two
type arguments, like Lambda Integer Natural
.
genericTypeDocDependencies :: forall a. (Generic a, GTypeHasDoc (Rep a)) => Proxy a -> [SomeDocDefinitionItem] Source #
Implement typeDocDependencies
via getting all immediate fields
of a datatype.
Note: this will not include phantom types, I'm not sure yet how this scenario should be handled (@martoon).
homomorphicTypeDocHaskellRep :: forall a. (Generic a, GTypeHasDoc (Rep a)) => TypeDocHaskellRep a Source #
Implement typeDocHaskellRep
for a homomorphic type.
Note that it does not require your type to be of IsHomomorphic
instance,
which can be useful for some polymorphic types which, for documentation
purposes, we want to consider homomorphic.
Example: Operation
is in fact polymorphic, but we don't want this fact to
be reflected in the documentation.
concreteTypeDocHaskellRep :: forall a b. (Typeable a, GenericIsoValue a, GTypeHasDoc (Rep a), HaveCommonTypeCtor b a) => TypeDocHaskellRep b Source #
Implement typeDocHaskellRep
on example of given concrete type.
This is a best effort attempt to implement typeDocHaskellRep
for polymorphic
types, as soon as there is no simple way to preserve type variables when
automatically deriving Haskell representation of a type.
unsafeConcreteTypeDocHaskellRep :: forall a b. (Typeable a, GenericIsoValue a, GTypeHasDoc (Rep a)) => TypeDocHaskellRep b Source #
Version of concreteTypeDocHaskellRep
which does not ensure
whether the type for which representation is built is any similar to
the original type which you implement a TypeHasDoc
instance for.
haskellRepNoFields :: TypeDocHaskellRep a -> TypeDocHaskellRep a Source #
Erase fields from Haskell datatype representation.
Use this when rendering fields names is undesired.
haskellRepMap :: (Text -> Text) -> TypeDocHaskellRep a -> TypeDocHaskellRep a Source #
Like haskellRepAdjust
, but can't add or remove field names.
haskellAddNewtypeField :: Text -> TypeDocHaskellRep a -> TypeDocHaskellRep a Source #
Add field name for newtype
.
Since newtype
field is automatically erased. Use this function
to add the desired field name.
haskellRepAdjust :: (Maybe Text -> Maybe Text) -> TypeDocHaskellRep a -> TypeDocHaskellRep a Source #
Adjust field names using a function. Can add or remove field names.
homomorphicTypeDocMichelsonRep :: forall a. KnownIsoT a => TypeDocMichelsonRep a Source #
Implement typeDocMichelsonRep
for homomorphic type.
concreteTypeDocMichelsonRep :: forall a b. (Typeable a, KnownIsoT a, HaveCommonTypeCtor b a) => TypeDocMichelsonRep b Source #
Implement typeDocMichelsonRep
on example of given concrete type.
This function exists for the same reason as concreteTypeDocHaskellRep
.
unsafeConcreteTypeDocMichelsonRep :: forall a b. (Typeable a, KnownIsoT a) => TypeDocMichelsonRep b Source #
Version of unsafeConcreteTypeDocHaskellRep
which does not ensure
whether the type for which representation is built is any similar to
the original type which you implement a TypeHasDoc
instance for.