[Haskell-beginners] Re: Enforcing Monad Laws
Brandon S Allbery KF8NH
allbery at ece.cmu.edu
Fri Jul 2 11:12:54 EDT 2010
-----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.)
- --
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-----
More information about the Beginners
mailing list