genType icon indicating copy to clipboard operation
genType copied to clipboard

Named arguments when exporting only a subset via an interface file?

Open sgrove opened this issue 2 years ago • 1 comments

I think it's not quite possible to get named arguments in the gentype output for resi files currently.

e.g.:

// .res
let parse = (uriString: string): uri => {


// .resi
@genType
let parse: string => uri

// .gen.tsx
export const parse: (_1:string) => uri = QueryBS.parse;

vs with no .resi file:

// .tsx
export const parse: (uriString:string) => uri = QueryBS.parse;

I understand this may or may not be possible with what's available to gentype, but it'd be nice to pass through named arguments (even via a gentype.as annotation. e.g. @genType let toString: [@genType.as("myUri") uri] => string)

sgrove avatar Jul 01 '22 22:07 sgrove

Wondering whether there's ever a case when one would want to "hide" the variable names used in the implementation. Can't think of one. Looks like just taking the info from the implementation, would work fine. genType has not used all the tricks in the book, but the editor support has, and it accesses all sort of info, from interface, implementation, original verbatim code, result of the parser etc. So one can assume that all that info is within reach in terms of what's possible.

cristianoc avatar Jul 02 '22 01:07 cristianoc

How involved do you think this would be @cristianoc? This would be a great addition when creating libraries to be consumed on the TS side.

lessp avatar Sep 12 '23 14:09 lessp

This should move to the compiler repo, where gentype now lives. I think exporting selected arguments is only possible in uncurried mode. Also, the function should take an object instead of several arguments, which is not how functions are compiled.

And zero cost means the function can't be wrapped.

In short, this is more a question about core language semantics than gentype, which will just follow what the compiler does.

cristianoc avatar Sep 12 '23 15:09 cristianoc

This repository is being archived. If you feel like the issue still relevant, please re-create it in the compiler repo. Thanks!

ryyppy avatar Nov 13 '23 13:11 ryyppy