This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
Remove dynamic type check in Static Binary instance. #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Authored by @mboes
Currently, a dynamic type check occurs when a static value is deserialized. The reason for this check is to preclude writing pathological functions such as
decode . encode
that make it possible to modify the phantom type parameter of the static value.However,
decode . encode
is arguably the same pattern asread . show
, which in general is unsafe (e.g. whenever phantom type parameters are involved) but not in any manner specific to static values. It is debatable whether we should defensively protect against the user writing such code through the use of extra Typeable constraints. For what is good for the goose is good for the gander, i.e. not just static values, yet we cannot hope to guarantee type safety whenever the representation of an abstract type is exported in any way.Moreover, this dynamic type check is redundant with a second type check that occurs when resolving static values, in 'unstatic'. One can construct all manner of static values and compose them, but they can only be used by resolving them. Hence a dynamic type check will occur at least once, i.e. at resolution time. There is, therefore, little value in doing a dynamic type check earlier, while each such type check has a non negligible performance cost.