コード例 #1
0
        public InvariantLawsTests(IInvariant <TF> invariant, IEqK <TF> eqK)
        {
            var invariantLaws = new InvariantLaws <TF>(invariant);

            Add("Invariant Identity", args =>
                invariantLaws.InvariantIdentity(args.LiftedA).Holds(eqK));

            Add("Invariant Composition", args =>
                invariantLaws
                .InvariantComposition(args.LiftedA, args.FuncAtoB, args.FuncBtoA, args.FuncBtoC, args.FuncCtoB)
                .Holds(eqK));
        }
コード例 #2
0
        public FlatMapLawsTests(IFlatMap <TF> flatMap, IEqK <TF> eqK) : base(flatMap, eqK)
        {
            var flatMapLaws = new FlatMapLaws <TF>(flatMap);

            Add("FlatMap Associativity", args =>
                flatMapLaws.FlatMapAssociativity(args.LiftedA, args.FuncAtoLiftedB, args.FuncBtoLiftedC).Holds(eqK));

            Add("FlatMap Consistent Apply", args =>
                flatMapLaws.FlatMapConsistentApply(args.LiftedA, args.LiftedFuncAtoB).Holds(eqK));

            Add("MProduct Consistency", args =>
                flatMapLaws.MProductConsistency(args.LiftedA, args.FuncAtoLiftedB).Holds(eqK));
        }
コード例 #3
0
        public MonadLawsTests(IMonad <TF> monad, IEqK <TF> eqK) : base(monad, eqK)
        {
            AddRange(new ApplicativeLawsTests <TF, TA, TB, TC>(monad, eqK));

            var monadLaws = new MonadLaws <TF>(monad);

            Add("Monad Left Identity", args =>
                monadLaws.MonadLeftIdentity(args.A, args.FuncAtoLiftedB).Holds(eqK));

            Add("Monad Right Identity", args =>
                monadLaws.MonadRightIdentity(args.LiftedA).Holds(eqK));

            Add("Map and FlatMap Coherence", args =>
                monadLaws.MapFlatMapCoherence(args.LiftedA, args.FuncAtoB).Holds(eqK));
        }
コード例 #4
0
        public ApplyLawsTests(IApply <TF> apply, IEqK <TF> eqK) : base(apply, eqK)
        {
            var applyLaws = new ApplyLaws <TF>(apply);

            Add("Apply Composition", args =>
                applyLaws.ApplyComposition(args.LiftedA, args.LiftedFuncAtoB, args.LiftedFuncBtoC).Holds(eqK));

            Add("Map2 Product Consistency", args =>
                applyLaws
                .Map2ProductConsistency(args.LiftedA, args.LiftedB, (a, b) => a.GetHashCode() == b.GetHashCode())
                .Holds(eqK));

            Add("ProductL Consistency", args =>
                applyLaws.ProductLConsistency(args.LiftedA, args.LiftedB).Holds(eqK));

            Add("ProductR Consistency", args =>
                applyLaws.ProductRConsistency(args.LiftedA, args.LiftedB).Holds(eqK));
        }
コード例 #5
0
        public ApplicativeLawsTests(IApplicative <TF> applicative, IEqK <TF> eqK) : base(applicative, eqK)
        {
            var applicativeLaws = new ApplicativeLaws <TF>(applicative);

            Add("Applicative Identity", args =>
                applicativeLaws.ApplicativeIdentity(args.LiftedA).Holds(eqK));

            Add("Applicative Homomorphism", args =>
                applicativeLaws.ApplicativeHomomorphism(args.A, args.FuncAtoB).Holds(eqK));

            Add("Applicative Interchange", args =>
                applicativeLaws.ApplicativeInterchange(args.A, args.LiftedFuncAtoB).Holds(eqK));

            Add("Applicative Map", args =>
                applicativeLaws.ApplicativeMap(args.LiftedA, args.FuncAtoB).Holds(eqK));

            Add("Ap Product Consistent", args =>
                applicativeLaws.ApProductConsistent(args.LiftedA, args.LiftedFuncAtoB).Holds(eqK));
        }
コード例 #6
0
        public FunctorLawsTests(IFunctor <TF> functor, IEqK <TF> eqK) : base(functor, eqK)
        {
            var functorLaws = new FunctorLaws <TF>(functor);

            Add("Covariant Identity", args =>
                functorLaws.CovariantIdentity(args.LiftedA).Holds(eqK));

            Add("CovariantComposition", args =>
                functorLaws.CovariantComposition(args.LiftedA, args.FuncAtoB, args.FuncBtoC).Holds(eqK));

            Add("Lift Identity", args =>
                functorLaws.LiftIdentity(args.LiftedA).Holds(eqK));

            Add("Lift Composition", args =>
                functorLaws.LiftComposition(args.LiftedA, args.FuncAtoB, args.FuncBtoC).Holds(eqK));

            Add("Void Identity", args =>
                functorLaws.VoidIdentity(args.LiftedA).Holds(eqK));

            Add("Void Composition", args =>
                functorLaws.VoidComposition(args.LiftedA).Holds(eqK));

            Add("FProduct Identity", args =>
                functorLaws.FProductIdentity(args.LiftedA, args.B).Holds(eqK));

            Add("FProduct Composition", args =>
                functorLaws
                .FProductComposition(args.LiftedA, args.FuncAtoB, ((TA a, TB b)ab) => args.FuncBtoC(ab.b))
                .Holds(eqK));

            Add("FProductLeft Identity", args =>
                functorLaws.FProductLeftIdentity(args.LiftedA, args.B).Holds(eqK));

            Add("FProductLeft Composition", args =>
                functorLaws
                .FProductLeftComposition(args.LiftedA, args.FuncAtoB, ((TB b, TA a)ba) => args.FuncBtoC(ba.b))
                .Holds(eqK));

            Add("As Identity", args =>
                functorLaws.AsIdentity(args.LiftedA, args.B).Holds(eqK));

            Add("As Composition", args =>
                functorLaws.AsComposition(args.LiftedA, args.B, args.C).Holds(eqK));

            Add("TupleLeft Identity", args =>
                functorLaws.TupleLeftIdentity(args.LiftedA, args.B).Holds(eqK));

            Add("TupleLeft Composition", args =>
                functorLaws.TupleLeftComposition(args.LiftedA, args.B, args.C).Holds(eqK));

            Add("TupleRight Identity", args =>
                functorLaws.TupleRightIdentity(args.LiftedA, args.B).Holds(eqK));

            Add("TupleRight Composition", args =>
                functorLaws.TupleRightComposition(args.LiftedA, args.B, args.C).Holds(eqK));

            Add("Unzip Identity", args =>
                functorLaws.UnzipIdentity(args.LiftedA, args.FuncAtoB) switch
            {
                var(a, b) => a.Holds(eqK) && b.Holds(eqK)
            }
コード例 #7
0
ファイル: IsEq.cs プロジェクト: chapiteau-team/Fnx
 public static bool Holds <TF, T>(this IsEq <IKind <TF, T> > self, IEqK <TF> eqK) =>
 self switch
 {