C# code contract: how to check associativity


hi,

i'm trying encode associativity of binary operation code contract.

below atempt far. sensible way ?

    public interface imagma<telem>
        telem : iequatable<telem>
    {
        [pure]
        telem mult(telem a, telem b);
    }

    public interface iassociativemagma<telem> :
        imagma<telem>
        telem : iequatable<telem>
    {

    }

    [contractclassfor(typeof(iassociativemagma<>))]     // can't put telem here
    internal abstract class associativemagmacontract<telem> :
        iassociativemagma<telem>
        telem : iequatable<telem>
    {
        [pure]
        public telem mult(telem a, telem b)
        {
            return default(telem);
        }

        [contractinvariantmethod]
        private void associativityproperty(telem a, telem b, telem c)      // complains that
        {
            // var = contract.any<telem>(); // idea
            contract.invariant(mult(mult(a, b), c).equals(mult(a, mult(b, c))));
        }
    }

    public class myassociativemagma : iassociativemagma<int>
    {
        [pure]
        public int mult(int a, int b)
        {
            return + b;
        }
    }


hi kikipoi,

thank posting here.

for question, refer msdn article code contracts.

in article, has explanation of specify preconditions, postconditions, , object invariants in code.

  • preconditions requirements must met when entering method or property.
  • postconditions describe expectations @ time method or property code exits.
  • object invariants describe expected state class in state.

i hope helpful you.

best regards,

wendy


msdn community support
please remember click "mark answer" responses resolved issue, , click "unmark answer" if not. can beneficial other community members reading thread. if have compliments or complaints msdn support, feel free contact msdnfsf@microsoft.com.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'