export type Cancel = ( k : ( e ? : Error ) => void ) => void ; export const uncancelable = ( k ) => k ( new Error ( 'uncancelable' ) ) ; export type Env < R , A > = ( r : R , k : ( a : A ) => Cancel ) => Cancel ; export type Subtract < T , T1 extends T > = Omit < T , keyof T1 > ; export type None = Subtract < { } , { } > ; export type Any = { } ; export const use = < RA , RB extends RA , A > ( rb , e ) : Env < Subtract < RA , RB > , A > => ( ra , k ) => e ( { ... rb , ... ra } as RA & RB , k ) ; export const runPure = < A > ( e , k = ( ) => uncancelable ) : Cancel => e ( { } , k ) ; export const pure = < A > ( a ) : Env < Any , A > => ( _ , k ) => k ( a ) ; export const map = < R , A , B > ( e , f ) : Env < R , B > => ( r , k ) => e ( r , a => k ( f ( a ) ) ) ; export const chain = < RA , RB , A , B > ( e , f ) : Env < RA & RB , B > => ( rab , k ) => e ( rab , a => f ( a ) ( rab , k ) ) ; export const withEnv = < R , A > ( f ) : Env < R , A > => ( r , k ) => k ( f ( r ) ) ; export const embed = < RA , RB , A > ( f , e ) : Env < RA , A > => ( ra , k ) => e ( f ( ra ) , k ) ;