[Haskell-cafe] Fwd: enhancing type classes with properties

Alberto G. Corona agocorona at gmail.com
Wed Oct 22 08:42:37 EDT 2008

I´m just thinking aloud, but, because incorporating deeper mathematics
concepts has proven to be the best solution for better and more flexible
programming languages with fewer errors, I wonder if raising the type
classes incorporating axioms can solve additional problems.

At first sight it does:

class Abelian a  where
    (+) :: a -> a -> a
    property ((+))= a+b == b+a

this permits:
   1- safer polimorphism:   I can safely reuse the operator + if the type
and the property is obeyed. The lack of ability to redefine operators is a
problem for DSLs that must use wreid symbols combinations with unknow
meanings. To use common operators with fixed properties is very good. the
same aplies for method names.

   2- the compiler can use the axions as rewrite rules.

  3- in debugging mode, it is possible to verify the axiom for each  value a
generated during execution. Thus, a generator  is not needed  like in
quickcheck. The logic to quickcheck can be incorporated in the debugging

3 guaranties  that 1 and 2 are safe.

a type class can express a relation between types,  but it is not possible
to define relation between relations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081022/c1466b23/attachment.htm

More information about the Haskell-Cafe mailing list