Skip to content

Higher order function type inference #30215

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

Merged
merged 20 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Accept new baselines
  • Loading branch information
ahejlsberg committed Mar 4, 2019
commit c58819e9c2248294da8cbdc76ce14ae8d0388536
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var e = <K>(x: string, y?: K) => x.length;
>length : number

var r99 = map(e); // should be {}[] for S since a generic lambda is not inferentially typed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this comment (and the one below on GH) need to be updated,

>r99 : (a: {}[]) => number[]
>map(e) : (a: {}[]) => number[]
>r99 : <K>(a: string[]) => number[]
>map(e) : <K>(a: string[]) => number[]
>map : <S, T>(f: (x: S) => T) => (a: S[]) => T[]
>e : <K>(x: string, y?: K) => number

Expand All @@ -37,8 +37,8 @@ var e2 = <K>(x: string, y?: K) => x.length;
>length : number

var r100 = map2(e2); // type arg inference should fail for S since a generic lambda is not inferentially typed. Falls back to { length: number }
>r100 : (a: { length: number; }[]) => number[]
>map2(e2) : (a: { length: number; }[]) => number[]
>r100 : <K>(a: string[]) => number[]
>map2(e2) : <K>(a: string[]) => number[]
>map2 : <S extends { length: number; }, T>(f: (x: S) => T) => (a: S[]) => T[]
>e2 : <K>(x: string, y?: K) => number

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var id: <T>(x:T) => T;
>x : T

var r23 = dot(id)(id);
>r23 : (_: {}) => {}
>dot(id)(id) : (_: {}) => {}
>r23 : <T>(_: T) => {}
>dot(id)(id) : <T>(_: T) => {}
>dot(id) : <U>(g: (_: U) => {}) => (_: U) => {}
>dot : <T, S>(f: (_: T) => S) => <U>(g: (_: U) => T) => (_: U) => S
>id : <T>(x: T) => T
Expand Down
26 changes: 13 additions & 13 deletions tests/baselines/reference/genericFunctionInference1.types
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ declare function box<V>(x: V): { value: V };
>value : V

const f00 = pipe(list);
>f00 : (a: any) => any[]
>pipe(list) : (a: any) => any[]
>f00 : <T>(a: T) => T[]
>pipe(list) : <T>(a: T) => T[]
>pipe : { <A extends any[], B>(ab: (...args: A) => B): (...args: A) => B; <A extends any[], B, C>(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; <A extends any[], B, C, D>(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; }
>list : <T>(a: T) => T[]

const f01 = pipe(list, box);
>f01 : (a: any) => { value: any[]; }
>pipe(list, box) : (a: any) => { value: any[]; }
>f01 : <T>(a: T) => { value: T[]; }
>pipe(list, box) : <T>(a: T) => { value: T[]; }
>pipe : { <A extends any[], B>(ab: (...args: A) => B): (...args: A) => B; <A extends any[], B, C>(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; <A extends any[], B, C, D>(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; }
>list : <T>(a: T) => T[]
>box : <V>(x: V) => { value: V; }
Expand All @@ -57,15 +57,15 @@ const f02 = pipe(x => list(x), box);
>box : <V>(x: V) => { value: V; }

const f03 = pipe(list, x => box(x));
>f03 : (a: any) => { value: any[]; }
>pipe(list, x => box(x)) : (a: any) => { value: any[]; }
>f03 : <T>(a: T) => { value: T[]; }
>pipe(list, x => box(x)) : <T>(a: T) => { value: T[]; }
>pipe : { <A extends any[], B>(ab: (...args: A) => B): (...args: A) => B; <A extends any[], B, C>(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; <A extends any[], B, C, D>(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; }
>list : <T>(a: T) => T[]
>x => box(x) : (x: any[]) => { value: any[]; }
>x : any[]
>box(x) : { value: any[]; }
>x => box(x) : (x: T[]) => { value: T[]; }
>x : T[]
>box(x) : { value: T[]; }
>box : <V>(x: V) => { value: V; }
>x : any[]
>x : T[]

const f04 = pipe(x => list(x), x => box(x))
>f04 : (x: any) => { value: any[]; }
Expand All @@ -83,11 +83,11 @@ const f04 = pipe(x => list(x), x => box(x))
>x : any[]

const f05 = pipe(list, pipe(box));
>f05 : (a: any) => { value: any[]; }
>pipe(list, pipe(box)) : (a: any) => { value: any[]; }
>f05 : <T>(a: T) => { value: T[]; }
>pipe(list, pipe(box)) : <T>(a: T) => { value: T[]; }
>pipe : { <A extends any[], B>(ab: (...args: A) => B): (...args: A) => B; <A extends any[], B, C>(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; <A extends any[], B, C, D>(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; }
>list : <T>(a: T) => T[]
>pipe(box) : (x: any[]) => { value: any[]; }
>pipe(box) : (x: T[]) => { value: T[]; }
>pipe : { <A extends any[], B>(ab: (...args: A) => B): (...args: A) => B; <A extends any[], B, C>(ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; <A extends any[], B, C, D>(ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; }
>box : <V>(x: V) => { value: V; }

Expand Down
20 changes: 10 additions & 10 deletions tests/baselines/reference/genericTypeParameterEquivalence2.types
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ function curry1<A, B, C>(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C {
}

var cfilter = curry1(filter);
>cfilter : (ax: {}) => (bx: {}) => {}[]
>curry1(filter) : (ax: {}) => (bx: {}) => {}[]
>cfilter : <A>(ax: (a: A) => boolean) => (bx: A[]) => A[]
>curry1(filter) : <A>(ax: (a: A) => boolean) => (bx: A[]) => A[]
>curry1 : <A, B, C>(f: (a: A, b: B) => C) => (ax: A) => (bx: B) => C
>filter : <A>(f: (a: A) => boolean, ar: A[]) => A[]

Expand All @@ -149,11 +149,11 @@ function countWhere_1<A>(pred: (a: A) => boolean): (a: A[]) => number {
>a : A[]

return compose(length2, cfilter(pred));
>compose(length2, cfilter(pred)) : (a: {}) => number
>compose(length2, cfilter(pred)) : (a: A[]) => number
>compose : <A, B, C>(f: (b: B) => C, g: (a: A) => B) => (a: A) => C
>length2 : <A>(ar: A[]) => number
>cfilter(pred) : (bx: {}) => {}[]
>cfilter : (ax: {}) => (bx: {}) => {}[]
>cfilter(pred) : (bx: A[]) => A[]
>cfilter : <A>(ax: (a: A) => boolean) => (bx: A[]) => A[]
>pred : (a: A) => boolean
}

Expand All @@ -164,14 +164,14 @@ function countWhere_2<A>(pred: (a: A) => boolean): (a: A[]) => number {
>a : A[]

var where = cfilter(pred);
>where : (bx: {}) => {}[]
>cfilter(pred) : (bx: {}) => {}[]
>cfilter : (ax: {}) => (bx: {}) => {}[]
>where : (bx: A[]) => A[]
>cfilter(pred) : (bx: A[]) => A[]
>cfilter : <A>(ax: (a: A) => boolean) => (bx: A[]) => A[]
>pred : (a: A) => boolean

return compose(length2, where);
>compose(length2, where) : (a: {}) => number
>compose(length2, where) : (a: A[]) => number
>compose : <A, B, C>(f: (b: B) => C, g: (a: A) => B) => (a: A) => C
>length2 : <A>(ar: A[]) => number
>where : (bx: {}) => {}[]
>where : (bx: A[]) => A[]
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy