-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Funfix integration #252
Comments
@gcanti is that tested against the master or next branch ? |
@alexandru maybe we could agree on the shape of // fp-ts
export interface HKT<URI, A> {
readonly _URI: URI
readonly _A: A
}
// funfix
export interface HK<F, A> {
/** Trick for achieving nominal typing. */
readonly _funKindF: F
/** Trick for achieving nominal typing. */
readonly _funKindA: A
} |
Hello, Yes, we can agree on an encoding. When I looked at yours a while back, it looked different than mine, but maybe I don't remember correctly. I don't really like I'll also work on Fantasy Land integration if that helps, there's a new issue opened for it. |
@alexandru opss, you are right, So the only choice seems to fix that module augmentation issue |
I don't know right now how that Would this work (without actually initializing those members)? class IO<A> {
readonly _URI: 'funfix/IO'
readonly _F: Option<any>
readonly _A: A
} |
Yes
Yes, just checked changing manually the definition file. However you would be forced to
I got it! This works declare module 'funfix-effect/dist/io' {
interface IO<A> {
_A: A
_URI: URI
}
} |
@alexandru @sledorze So these are the steps in order to integrate a funfix data type import { Future } from 'funfix-exec'
// step 1: choose a unique string literal representing the data type
export const URI = 'funfix/Future'
export type URI = typeof URI
// step 2: module augmentation of the original source
declare module 'funfix-exec/dist/future' {
interface Future<A> {
_A: A
_URI: URI
}
}
// step 3: HKT module augmentation
declare module 'fp-ts/lib/HKT' {
interface URI2HKT<A> {
'funfix/Future': Future<A>
}
}
// step 4: define type class instances
import { Monad } from 'fp-ts/lib/Monad'
export const map = <A, B>(f: (a: A) => B, fa: Future<A>): Future<B> => fa.map(f)
export const of = <A>(a: A): Future<A> => Future.pure(a)
export const ap = <A, B>(fab: Future<(a: A) => B>, fa: Future<A>): Future<B> => fab.flatMap(f => fa.map(f))
export const chain = <A, B>(f: (a: A) => Future<B>, fa: Future<A>): Future<B> => fa.flatMap(f)
export const future: Monad<URI> = {
URI,
map,
of,
ap,
chain
} Then you can use import { liftA2 } from 'fp-ts/lib/Apply'
const sum = (a: number) => (b: number) => a + b
// sumA2: (a: Future<number>) => (b: Future<number>) => Future<number>
const sumA2 = liftA2(future)(sum)
sumA2(Future.pure(2))(Future.pure(2))
.toPromise()
.then(x => console.log(x))
// => 4 That's pretty cool |
I described a more idiomatic way to specify HKTs in #156. Maybe there's a similar spec we could use to better integrate all possible future libraries? |
It would be a good idea to have a common protocol for higher kinds actually. |
@alexandru @gcanti @SimonMeskens Yes! let's pave the road for 'type level' quality libs in typescript land :) |
Several things on that front: One is really the interop of the libraries because of base types: like https://github.com/gcanti/io-ts/blob/master/src/index.ts#L20 So we need a conversion layer to switch back and forth if the types are differents. Maybe interrop between those libs is too much work and a non goal and that issue can be closed. @gcanti @alexandru what do you think? |
@gcanti I am experimenting with your encoding for I'm guessing that the current shape is fairly stable, right? export interface HKT<URI, A> {
readonly _URI: URI
readonly _A: A
} |
@alexandru Yes, it is |
(follow up of #251 (comment))
@sledorze a basic integration looks possible
Not sure why I can't define a module augmentation though
The text was updated successfully, but these errors were encountered: