import { Functor1 } from 'fp-ts/lib/Functor' ; import { Fix , fix } from './Fix' ; declare module 'fp-ts/lib/HKT' { interface URI2HKT < A > { Nat : NatF < A > ; } } export const URI = 'Nat' ; export type URI = typeof URI ; export class Zero < A > { static value = new Zero < any > ( ) ; public value : never ; readonly _tag : 'Zero' = 'Zero' ; readonly '_A' : A ; readonly '_URI' : URI ; private constructor ( ) { } map < B > ( _f ) { return this as any ; } } export class Succ < A > { readonly _tag : 'Succ' = 'Succ' ; readonly '_A' : A ; readonly '_URI' : URI ; constructor ( public value ) { } map < B > ( f ) { return new Succ ( f ( this . value ) ) ; } } export type NatF < A > = Zero < A > | Succ < A > ; export type Nat = Fix < URI > ; export const zero = fix ( Zero . value ) ; export const succ = ( n ) : Nat => fix ( new Succ ( n ) ) ; export const functorNat = { URI , map < A , B > ( nat , f ) { return nat . map ( f ) ; } , } ;