static-land
static-land copied to clipboard
Flow/TypeScript
I have no idea what can be done in this area yet, but wanted to open an issue for general discussion on the topic.
Some relevant links:
https://github.com/donnut/typescript-ramda/ https://github.com/facebook/flow/issues/172
Related: https://github.com/fantasyland/fantasy-land/issues/140
Might be related: https://github.com/facebook/flow/issues/30
@rpominov I think Microsoft/TypeScript#1213 and Microsoft/TypeScript#7848 are equally as related as facebook/flow#30.
@rpominov I wrote a POC for Flow here
@gcanti I'll need to look closer at it, but seems that you've solved problem with higher kinded types using the HKT
helper. That's great!
@gcanti Is flow-static-land
more like an experiment or something that can be used in production? Asking because maybe we should add it to the list https://github.com/rpominov/static-land/wiki/Compatible-libraries
@rpominov I'd say that now is more than an experiment. I'm working on it full time and seems really promising. In the last few days I ported some PureScript libraries and it's quite straightforward. I don't think is production ready though: tests are missing and there are some issues that must be solved, first of all how to publish / distribute the code (not yet sure what's the blessed way, shadow files? libdef? raw sources like now?). Also, I'd like to apply what I wrote so far to a real world case: I just started porting the QuickCheck library. If succesful it would be a nice proof that it can be used for "real" development.
Great, sounds like it have potential to become useful in production. I'll add to the list.
Do you think the same HKT technique would work for TypeScript?
@laurence-myers Yes, but due to TypeScript's lack of nominal typing, it'd remove all type safety from it.
@isiahmeadows I'm just learning TypeScript but what about something like this?
// Functor.js
type HKT<F, A> = { type: 'HKT', F: F, A: A };
export interface Functor<F> {
map<A, B>(f: (a: A) => B, fa: HKT<F, A>): HKT<F, B>
}
// Arr.js
export type Arr<A> = HKT<'Arr', A>;
export function inj<A>(a: Array<A>): Arr<A> {
return a as any as Arr<A>
}
export function prj<A>(fa: Arr<A>): Array<A> {
return fa as any as Array<A>
}
export function map<A, B>(f: (a: A) => B, fa: Arr<A>): Arr<B> {
return inj(prj(fa).map(f))
}
Just pushed a proof of concept here: https://github.com/gcanti/ts-static-land.
Though I'm not sure why sometimes I have to specify so many type parameters, for example here
https://github.com/gcanti/ts-static-land/blob/master/src/Identity.ts#L67
or here
https://github.com/gcanti/ts-static-land/blob/master/src/Maybe.ts#L118
Isn't TypeScript able to infer those types? Or is there a deeper problem in my code or with the HKT
abstraction?
I heard type inference is much more limited in TypeScript, don't know much about it though.
@rpominov FYI I'm working on https://github.com/gcanti/fp-ts (TypeScript) which supersedes my previous attempt. One of the main goals is to be compatible with both fantasy-land and static-land (hopefully)
That's great, @gcanti ! Thank you for doing all this research!