static-land icon indicating copy to clipboard operation
static-land copied to clipboard

Flow/TypeScript

Open rpominov opened this issue 8 years ago • 15 comments

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

rpominov avatar Mar 22 '16 00:03 rpominov

Related: https://github.com/fantasyland/fantasy-land/issues/140

rpominov avatar May 14 '16 21:05 rpominov

Might be related: https://github.com/facebook/flow/issues/30

rpominov avatar Jun 09 '16 10:06 rpominov

@rpominov I think Microsoft/TypeScript#1213 and Microsoft/TypeScript#7848 are equally as related as facebook/flow#30.

dead-claudia avatar Aug 13 '16 00:08 dead-claudia

@rpominov I wrote a POC for Flow here

gcanti avatar Aug 14 '16 13:08 gcanti

@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!

rpominov avatar Aug 14 '16 13:08 rpominov

@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 avatar Aug 23 '16 15:08 rpominov

@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.

gcanti avatar Aug 23 '16 15:08 gcanti

Great, sounds like it have potential to become useful in production. I'll add to the list.

rpominov avatar Aug 23 '16 15:08 rpominov

Do you think the same HKT technique would work for TypeScript?

laurence-myers avatar Sep 06 '16 00:09 laurence-myers

@laurence-myers Yes, but due to TypeScript's lack of nominal typing, it'd remove all type safety from it.

dead-claudia avatar Sep 06 '16 00:09 dead-claudia

@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))
}

gcanti avatar Nov 20 '16 12:11 gcanti

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?

gcanti avatar Nov 20 '16 18:11 gcanti

I heard type inference is much more limited in TypeScript, don't know much about it though.

rpominov avatar Nov 20 '16 19:11 rpominov

@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)

gcanti avatar Feb 17 '17 17:02 gcanti

That's great, @gcanti ! Thank you for doing all this research!

rpominov avatar Feb 17 '17 18:02 rpominov