since import * as fc from 'fast-check' ; import { Applicative , Applicative1 , Applicative2 , Applicative2C , Applicative3 } from 'fp-ts/lib/Applicative' ; import { Apply , Apply1 , Apply2 , Apply2C , Apply3 } from 'fp-ts/lib/Apply' ; import { Eq , eqBoolean , eqNumber , eqString } from 'fp-ts/lib/Eq' ; import { Field } from 'fp-ts/lib/Field' ; import { Functor , Functor1 , Functor2 , Functor2C , Functor3 } from 'fp-ts/lib/Functor' ; import { HKT , Kind , Kind2 , Kind3 , URIS , URIS2 , URIS3 } from 'fp-ts/lib/HKT' ; import { Monad , Monad1 , Monad2 , Monad2C , Monad3 } from 'fp-ts/lib/Monad' ; import { Monoid } from 'fp-ts/lib/Monoid' ; import { Ord } from 'fp-ts/lib/Ord' ; import { Ring } from 'fp-ts/lib/Ring' ; import { Semigroup } from 'fp-ts/lib/Semigroup' ; import { Semiring } from 'fp-ts/lib/Semiring' ; import * as laws from './laws' ; since export const eq = < A > ( E , arb ) : void => { const reflexivity = fc . property ( arb , laws . eq . reflexivity ( E ) ) ; const symmetry = fc . property ( arb , arb , laws . eq . simmetry ( E ) ) ; const transitivity = fc . property ( arb , arb , arb , laws . eq . transitivity ( E ) ) ; fc . assert ( reflexivity ) ; fc . assert ( symmetry ) ; fc . assert ( transitivity ) ; } ; since export const ord = < A > ( O , arb ) : void => { eq ( O , arb ) ; const totality = fc . property ( arb , arb , laws . ord . totality ( O ) ) ; const reflexivity = fc . property ( arb , laws . ord . reflexivity ( O ) ) ; const antisymmetry = fc . property ( arb , arb , laws . ord . antisimmetry ( O ) ) ; const transitivity = fc . property ( arb , arb , arb , laws . ord . transitivity ( O ) ) ; fc . assert ( totality ) ; fc . assert ( reflexivity ) ; fc . assert ( antisymmetry ) ; fc . assert ( transitivity ) ; } ; example since export const semigroup = < A > ( S , E , arb ) : void => { const associativity = fc . property ( arb , arb , arb , laws . semigroup . associativity ( S , E ) ) ; fc . assert ( associativity ) ; } ; since export const monoid = < A > ( M , E , arb ) : void => { semigroup ( M , E , arb ) ; const rightIdentity = fc . property ( arb , laws . monoid . rightIdentity ( M , E ) ) ; const leftIdentity = fc . property ( arb , laws . monoid . leftIdentity ( M , E ) ) ; fc . assert ( rightIdentity ) ; fc . assert ( leftIdentity ) ; } ; since export const semiring = < A > ( S , E , arb , seed ? ) : void => { const addAssociativity = fc . property ( arb , arb , arb , laws . semiring . addAssociativity ( S , E ) ) ; const addIdentity = fc . property ( arb , laws . semiring . addIdentity ( S , E ) ) ; const commutativity = fc . property ( arb , arb , laws . semiring . commutativity ( S , E ) ) ; const mulAssociativity = fc . property ( arb , arb , arb , laws . semiring . mulAssociativity ( S , E ) ) ; const mulIdentity = fc . property ( arb , laws . semiring . mulIdentity ( S , E ) ) ; const leftDistributivity = fc . property ( arb , arb , arb , laws . semiring . leftDistributivity ( S , E ) ) ; const rightDistributivity = fc . property ( arb , arb , arb , laws . semiring . rightDistributivity ( S , E ) ) ; const annihilation = fc . property ( arb , laws . semiring . annihilation ( S , E ) ) ; fc . assert ( addAssociativity , { seed } ) ; fc . assert ( addIdentity , { seed } ) ; fc . assert ( commutativity , { seed } ) ; fc . assert ( mulAssociativity , { seed } ) ; fc . assert ( mulIdentity , { seed } ) ; fc . assert ( leftDistributivity , { seed } ) ; fc . assert ( rightDistributivity , { seed } ) ; fc . assert ( annihilation , { seed } ) ; } ; since export const ring = < A > ( R , S , arb , seed ? ) : void => { semiring ( R , S , arb , seed ) ; const additiveInverse = fc . property ( arb , laws . ring . additiveInverse ( R , S ) ) ; fc . assert ( additiveInverse ) ; } ; since export const field = < A > ( F , S , arb , seed ? ) : void => { ring ( F , S , arb , seed ) ; if ( S . equals ( F . zero , F . one ) ) { throw new Error ( `one should not be equal to zero` ) ; } const commutativity = fc . property ( arb , arb , laws . field . commutativity ( F , S ) ) ; const integralDomain = fc . property ( arb , arb , laws . field . integralDomain ( F , S ) ) ; const nonNegativity = fc . property ( arb , laws . field . nonNegativity ( F , S ) ) ; const quotient = fc . property ( arb , arb , laws . field . quotient ( F , S ) ) ; const reminder = fc . property ( arb , arb , laws . field . reminder ( F , S ) ) ; const submultiplicative = fc . property ( arb , arb , laws . field . submultiplicative ( F , S ) ) ; const inverse = fc . property ( arb , laws . field . inverse ( F , S ) ) ; fc . assert ( commutativity , { seed } ) ; fc . assert ( integralDomain , { seed } ) ; fc . assert ( nonNegativity , { seed } ) ; fc . assert ( quotient , { seed } ) ; fc . assert ( reminder , { seed } ) ; fc . assert ( submultiplicative , { seed } ) ; fc . assert ( inverse , { seed } ) ; } ; since export function functor < F extends URIS3 > ( F ) ; export function functor < F extends URIS2 > ( F ) ; export function functor < F extends URIS2 , L > ( F ) ; export function functor < F extends URIS > ( F ) ; export function functor < F > ( F ) ; export function functor < F > ( F ) { return ( lift , liftEq ) => { const arb = lift ( fc . string ( ) ) ; const Sa = liftEq ( eqString ) ; const Sc = liftEq ( eqNumber ) ; const identity = fc . property ( arb , laws . functor . identity ( F , Sa ) ) ; const ab = ( s ) : number | undefined | null => ( s . length === 1 ? undefined : s . length === 2 ? null : s . length ) ; const bc = ( n ) : number => ( n === undefined ? 1 : n === null ? 2 : n * 2 ) ; const composition = fc . property ( arb , laws . functor . composition ( F , Sc , ab , bc ) ) ; fc . assert ( identity ) ; fc . assert ( composition ) ; } ; } since export function apply < F extends URIS3 > ( F ) ; export function apply < F extends URIS2 > ( F ) ; export function apply < F extends URIS2 , L > ( F ) ; export function apply < F extends URIS > ( F ) ; export function apply < F > ( F ) ; export function apply < F > ( F ) { const functorF = functor ( F ) ; return ( lift , liftEq ) => { functorF ( lift , liftEq ) ; const Sc = liftEq ( eqBoolean ) ; const arbFa = lift ( fc . string ( ) ) ; const arbFab = lift ( fc . constant ( ( a ) => a . length ) ) ; const arbFbc = lift ( fc . constant ( ( b ) => b > 2 ) ) ; const associativeComposition = fc . property ( arbFa , arbFab , arbFbc , laws . apply . associativeComposition ( F , Sc ) ) ; fc . assert ( associativeComposition ) ; } ; } since export function applicative < F extends URIS3 > ( F ) ; export function applicative < F extends URIS2 > ( F ) ; export function applicative < F extends URIS2 , L > ( F ) ; export function applicative < F extends URIS > ( F ) ; export function applicative < F > ( F ) ; export function applicative < F > ( F ) { const applyF = apply ( F ) ; return ( lift , liftEq ) => { applyF ( lift , liftEq ) ; const arbFa = lift ( fc . string ( ) ) ; const Sa = liftEq ( eqString ) ; const Sb = liftEq ( eqNumber ) ; const identity = fc . property ( arbFa , laws . applicative . identity ( F , Sa ) ) ; const ab = ( s ) => s . length ; const homomorphism = fc . property ( fc . string ( ) , laws . applicative . homomorphism ( F , Sb , ab ) ) ; const arbFab = lift ( fc . constant ( ab ) ) ; const interchange = fc . property ( fc . string ( ) , arbFab , laws . applicative . interchange ( F , Sb ) ) ; const derivedMap = fc . property ( arbFa , laws . applicative . derivedMap ( F , Sb , ab ) ) ; fc . assert ( identity ) ; fc . assert ( homomorphism ) ; fc . assert ( interchange ) ; fc . assert ( derivedMap ) ; } ; } since export function monad < M extends URIS3 > ( M ) ; export function monad < M extends URIS2 > ( M ) ; export function monad < M extends URIS2 , L > ( M ) ; export function monad < M extends URIS > ( M ) ; export function monad < M > ( M ) ; export function monad < M > ( M ) { const applicativeM = applicative ( M ) ; return liftEq => { applicativeM ( arb => arb . map ( M . of ) , liftEq ) ; const Sc = liftEq ( eqBoolean ) ; const arbFa = fc . string ( ) . map ( M . of ) ; const afb = ( s ) => M . of ( s . length ) ; const bfc = ( n ) => M . of ( n > 2 ) ; const associativity = fc . property ( arbFa , laws . chain . associativity ( M , Sc , afb , bfc ) ) ; const Sb = liftEq ( eqNumber ) ; const fab = M . of ( ( a ) => a . length ) ; const derivedAp = fc . property ( arbFa , laws . chain . derivedAp ( M , Sb , fab ) ) ; fc . assert ( associativity ) ; fc . assert ( derivedAp ) ; const arb = fc . string ( ) . map ( M . of ) ; const Sa = liftEq ( eqString ) ; const leftIdentity = fc . property ( fc . string ( ) , laws . monad . leftIdentity ( M , Sb , afb ) ) ; const rightIdentity = fc . property ( arb , laws . monad . rightIdentity ( M , Sa ) ) ; const ab = ( s ) => s . length ; const derivedMap = fc . property ( arb , laws . monad . derivedMap ( M , Sb , ab ) ) ; fc . assert ( leftIdentity ) ; fc . assert ( rightIdentity ) ; fc . assert ( derivedMap ) ; } ; }