Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Internal structure of a Registry and associated functions
Synopsis
- findValueOrSpecialization :: SomeTypeRep -> Context -> Specializations -> Values -> Maybe (Either Specialization Value)
- findBestSpecializationFromApplicable :: SomeTypeRep -> Context -> Specializations -> Maybe Specialization
- findCompatibleCreatedValue :: SomeTypeRep -> Specializations -> Values -> Maybe Value
- storeValue :: Modifiers -> Value -> Stack Value
Documentation
findValueOrSpecialization :: SomeTypeRep -> Context -> Specializations -> Values -> Maybe (Either Specialization Value) Source #
Find a value having a target type from: - a list of "preferred values" (Specializations) to select when we are trying to find the target in a specific context (Context). Context describes the types of values we are currently trying to (recursively) make
- a list of already created values (Values)
3 subtleties: 1. if there are specialized values we need to find the most specialized for the current context, that is the one having its "targetType" the "lowest" in the values graph
- if an already created value has the right type but if it is a specialization and the type we are looking for is not in the specialization context then we cannot use that value, we need to recreate a brand new one
- if an already created value has the right type and is not specialized but if there is an incompatible specialization for one of its dependencies then it cannot be used
findBestSpecializationFromApplicable :: SomeTypeRep -> Context -> Specializations -> Maybe Specialization Source #
Among all the applicable specializations take the most specific one if there exists any
findCompatibleCreatedValue :: SomeTypeRep -> Specializations -> Values -> Maybe Value Source #
Among all the created values, take a compatible one
- 2. and 3. if that value is a specialized value or has specialized dependencies it must be compatible with the current context
storeValue :: Modifiers -> Value -> Stack Value Source #
Given a newly built value, check if there are modifiers for that
value and apply them before "storing" the value which means
adding it on top of the registry, represented by the Values
state
in StateT Values.
We use a StateT Either because applying modifiers could fail and we want
to catch and report the error. Note that this error would be an implementation
error (and not a user error) since at the type-level everything should be correct