[Haskell-beginners] Re: Enforcing Monad Laws

Jorden M jrm8005 at gmail.com
Fri Jul 2 15:40:16 EDT 2010


On Fri, Jul 2, 2010 at 11:12 AM, Brandon S Allbery KF8NH
<allbery at ece.cmu.edu> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 7/2/10 04:04 , Heinrich Apfelmus wrote:
>> Jorden M wrote:
>>> C++ `Concepts', which almost made it into the C++0x standard, are
>>> roughly similar to Haskell type classes. The proposal for concepts in
>>> C++ had a feature called axioms, which allow the programmer to specify
>>> semantics on the functions the concept contains. This allows for
>>> enforcing things such as the Monad Laws, as well as letting the
>>> compiler make certain optimizations it may not have been able to make
>>> without axiomatic guarantees.
>>
>> I have a hard time imagining that axioms are being used to prove properties
>> about programs in a language such as C++... :) Any pointers?
>
> I just took a look at it, and Concepts look to me like Haskell
> contexts/constraints; an example is:
>
>> concept LessThanComparable<typename T> {
>>   bool operator<(const T& x, const T& y);
>> }
>>
>> template<typename T>
>> requires LessThanComparable<T>
>> const T& min(const T& x, const T& y) {
>>   return x < y? x : y;
>> }
>
> which is obviously just an Ord costraint on min().
>
> (My initial thought before looking at this was that it was programming by
> contract, or possibly just making invariants explicit; the latter wouldn't
> actually prove anything, though.)

requires statements are like contexts. concepts are like type classes.
concept_maps are like instances.

The particular feature I'm talking about are axioms, which go inside
concepts, and allow the programmer to express certain semantic
behavior, such as commutativity. Currently, such things are left to
the `honest' programmer in Haskell.

>
> - --
> brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
> system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university      KF8NH
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.10 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkwuAfYACgkQIn7hlCsL25URBQCeOsh3m3jfmifLeG8kzLC6Df74
> PU4AoJwho/HN9IClcBw6RTN6kzVxRvX1
> =B0SX
> -----END PGP SIGNATURE-----
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list