[#737] Add `HasRPCRepr` typeclass
Description
Problem: The AsRPC
type family has an unenforced law:
ToT (AsRPC t) ~ AsRPC (ToT t)
This law basically ensures that ToT
and AsRPC
are commutative
Storage ----------(applying ToT)-------------> ToT Storage
| |
| |
| |
(applying AsRPC) (applying AsRPC)
| |
| |
| |
| V
| AsRPC (ToT Storage)
V ~
AsRPC Storage ------(applying ToT)-----------> ToT (AsRPC Storage)
This, in turn, means you can go from some type Storage
to AsRPC Storage
by
composing fromVal . valueAsRPC . toVal
:
Storage ------------(toVal)--------------> Value (ToT Storage)
| |
| |
| |
(fromVal . valueAsRPC . toVal) (valueAsRPC)
| |
| |
| |
| V
| Value (AsRPC (ToT Storage))
V ~
AsRPC Storage <--------(fromVal)--------- Value (ToT (AsRPC Storage))
This law is not enforced by the type system, though we do have some
smoke tests in Test.AsRPC
.
However, in #737 (closed), we will need to make use of this law, so we need to formalize it and enforce it.
Solution:
- Wrap the
AsRPC
type family in aHasRPCRepr
typeclass. - We can now add this law as a superclass of
HasRPCRepr
, therefore enforcing it.
The kind signature of the AsRPC
type family is AsRPC :: k -> k
. It
is polykinded because we need it to work for kinds T
and Type
.
However, this law only holds for Type
, not for T
. Therefore, we had
to split the AsRPC :: k -> k
type family in two:
- an open type family:
AsRPC :: Type -> Type
- a closed type family:
TAsRPC :: T -> T
Incidentally, ended up discovering these AsRPC
instances were not lawful:
OpenChestT
View_
Void_
ShouldHaveEntrypoints
Related issue(s)
Resolves part of #737 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.