-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
allow type parameters on type arguments #5959
Comments
From reading your example, it looks to me like you're wanting existential types? Keep in mind that I haven't really done any typescript before - so there's likely a nicer way to do what I came up with: type Exists =
<r> (go : <t> (_ : Command<t>) => r) => r
const exists = <c> (command : Command<c>) : Exists =>
<r> (go : <t> (_ : Command<t>) => r) : r => go(command)
let knownCommands : Map<Exists> = {
'copy': exists(<Command<CopyCommandOptions>> undefined),
'clean': exists(<Command<CleanCommandOptions>> undefined)
};
let args : string[]
knownCommands[name](<t> (command : Command<t>) => {
command.run(command.read(args));
}); Does that roughly do what you want in this case? @Aleksey-Bykov |
@LiamGoodacre |
😄 Also to highlight that the read/run types match up: knownCommands[a](<t> (x : Command<t>) => {
knownCommands[b]<s> (y : Command<s>) => {
//x.run(y.read(args)); // type error, `s` is not `t`
//y.run(x.read(args)); // type error, `t` is not `s`
x.run(x.read(args)); // fine
y.run(y.read(args)); // fine
});
}); |
This may be useful as an example of existential types as a library: https://github.com/purescript/purescript-exists/blob/master/docs/Data/Exists.md |
This hasn't gotten a concrete proposal yet and I imagine there are more well-fleshed-out issues on it by now |
The text was updated successfully, but these errors were encountered: