-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First class type constructor #35816
Labels
Duplicate
An existing issue was already created
Comments
RyanCavanaugh
added
the
Needs More Info
The issue still hasn't been fully clarified
label
Jan 13, 2020
What's the differentiation between this and #1213 or other HKT issues? |
Follow-up proposalType Extensiontype <T>.Foo = [T]
type foo = 1.Foo // foo is [1]
type <A>.Bar<B> = [A, B]
type bar = 1.Bar<2> // bar is [1, 2] type <O>.Omit<K> = Omit<O, K>
type <O>.Keys= keyof O
type <O>.Vals = O[O.Keys]
type <O>.Map<F extends for<[O.Keys, O.Vals]>> = { [K in O.Keys]: F<K, O[K]> }
type OmitValue<O, T> = O.Omit<O.Map<for<K, V> V extends T ? K : never>.Vals>
// same to
type OmitValue<O, T> = Omit<O, { [K in keyof O]: O[K] extends T ? K : never }[keyof O]> |
This is exactly what I'm looking for. |
RyanCavanaugh
added
Duplicate
An existing issue was already created
and removed
Needs More Info
The issue still hasn't been fully clarified
labels
Aug 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Search Terms
first class type alias constructor hkt variadic generics transitivity independent independence first-class first-class-type first-class-type-alias first-class-type-constructor variadic-generics higher-kinded-types hrt higher kinded rank types rank-n
Suggestion
Add first class type constructor support
This proposal contains the following features
HKT
The following uses this
'type' ('<' <args>,+ '>')? <return>?
syntaxalthough this syntax has compatibility issues
This is already very useful, but there are many other problems
Transitivity & Independence
Playground
Because it is not transitive, generics are discarded during inference,
so we need the type constructor to be transitive,
and this requires that the type constructor must be independent
with transitivity and independence, this will be
Independent type constructor should not exist at runtime,
so when an independent type constructor is used as a type without being applied,
the generic type should be discarded again
The transitivity of type constructors should also exist on type aliases
*
This
type
syntax is very loose,You can represent not only type constructors with parameters,
but also type constructors without parameters,
or you can optionally fill in the return type in the type parameter
Variadic Generics
The current improvised solution is
Normally this is enough, but it is not free enough when the type constructor is transitive
if has variadic generics, then the type constructor can be inferred
Variadic syntax
Infer TypeReturnType
Infer TypeParameters
Compatibility
It is a pity that although this
type
syntax is very readable, it has compatibility issuesOther possible syntax
What is First class Type constructor
* -> *
is type constructor(* -> *) -> *
is HKT* -> * -> *
is binary type constructor with currying(* -> *) -> (* -> *)
is first class type constructor without currying but with transitivity, independentExamples
Checklist
My suggestion meets these guidelines:
Reference
#1213
#1213 (comment)
#5959
#29904
#30215
#31116
#41040
#44875
#48036
#48820
first-class-protocols
The text was updated successfully, but these errors were encountered: