You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is some doc about T module in :ex_type_runtime package at here.
The :ex_type_runtime is used to provide following advanced features:
1. Generic Protocol support with T.p(ProtocolModule, generic_type) Type
Take Enumerable protocol as example. The enumerable integers would be represented as T.p(Enumerable, integer()). Ideally, this should be something like Enumerable.t(integer()) instead, but Enumerable.t/1 does not exist and other type checker like dialyzer would complain if it's been used. Therefore, T.p(Enumerable, x) is used to simulate Enumerable.t(x).
2. Intersection Type support with T.&({ type_1, type_2, type3 }) Type
Intersection type is useful to represent some combination of types.
For example, T.&({ Inspect.t, String.Chars.t }) would represent a type that implements both Inspect and String.Chars protocols.
Note: this feature is not complete yet.
3. Type Assertion with T.assert macro
T.assert is used to do type assertion. It supports two operators.
a. T.assert( expr :: type ) is used to cast type. Similar to as in TypeScript.
b. T.assert( expr == expected_type ) is used to ensure the inferred type is the same as expected one. Type check would fail if it's not the same. Note that it won't cause any exception when the program is running regularly (when not doing type checking with ExType).
T.inspect is used to inspect inferred type. Like IO.inspect, T.inspect( expr ) will print out the inferred type of expr when ExType is doing type checking. Note that it won't print anything when program is running regularly (when not doing type checking with ExType).
Basically, above features require some minimal runtime support. If we want to commit code that includes above advanced features, we would need to add :ex_type_runtime as runtime dependency.
p.s. the name of package :ex_type_runtime was originally named as :t (so its consistent with module T). But I found out that hex.pm requires package name to be at least two characters when publishing. Therefore, I rename package name to :ex_type_runtime.
Reading both this README and the one from ex_type_runtime I'm unsure what it would provide. A little information on that would help a long way!
Thanks for doing this project, sounds interesting. Curious to see where it goes 🎉
The text was updated successfully, but these errors were encountered: