0

Have this:

type Format<A, R> = (arg: A) => R;

type FormatString<R> = (str: string) => R;

type FormatNumber<R> = (num: number) => R;

Would like to have this:

type Format<A<R>> = (arg: A) => R;

type FormatString = Format<string>;

type FormatNumber = Format<number>;

Or this:

type Format<A, R> = (arg: A) => R;

type FormatString = Format<string>;

type FormatNumber = Format<number>;

Currying or partial application for types is what I'm looking for. Or maybe some other workaround which keeps the code dry.

2
  • Without higher-kinded types this is not really possible without duplication. Commented Jul 31, 2018 at 17:10
  • Do you have a use case for this? Commented Jul 31, 2018 at 17:14

1 Answer 1

3

Just add R as another type parameter on the partially specialized types.

type Format<A, R> = (arg: A) => R;

type FormatString<R> = Format<string, R>;

type FormatNumber<R> = Format<number, R>;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.