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
I'm no expert but I think the problem is related to the array of pairs not having the same type. If all the pairs operated on a stream of the same type then the AccumPair that you propose
export declare type AccumPair<A, C> = [Stream<C>, (a: C, b: A) => A];
would actually work.
Maybe one could may it type safe in a language having both rank-n polymorphism and existential types. The type of accumCombine would then be:
accumCombine : forall a.Array (exists b. (Stream b, b -> a -> a)) ->Stream a
I'm not sure if it makes sense, but I'm saying that all the pairs have the type exists b. (Stream b, b -> a -> a). I.e. that there exists a type b such that the first element in pair has type Stream b and the second element has type b -> a -> a. That holds true for all the pairs so now they have the same type since the exists quantifier binds the varying type for each of the pairs.
We actually could make accumCombine type-safe in TypeScript up to some maxium number of elements in the array by overloading it. For instance, this overloaded type is type-safe for up to 3 arguments:
I noticed while looking at TodoMVC that the following isn't fully typesafe,
where
prependItemS: Stream<A>
andremoveKeyListS: Stream<B[]>
, butitem: any
andkeys: any
.I looked at the types,
I see that if you do this
It won't work because C will get bound once to the first element of the first element of
pairs
.Is rank-n polymorphism what is needed here? I've read about it a bit. Does TS support it?
The text was updated successfully, but these errors were encountered: